First time here? Checkout the FAQ!
+6 votes
a 4-ary tree has either 4 or 0 children,What is the total number of nodes when there are 20 leaf node?
asked in Programming by Veteran (18.4k points)   | 200 views

3 Answers

+10 votes
Best answer
Ans. Not possible. 20 leaf nodes arrangement for given constraint of 0 or 4 children


I:- no. Of internal nodes

L:- no. Of leaf node

n:- n- ary tree

If u analyze some what you will get following formula:-->>

(n-1) I +1 = L

But for Given question due to ur given constraint of 0 or 4 children

20 leaf nodes are not possible in this arrangment.

If 19 leaf nodes given then we have a solution for this :->> apply on above formula u will get 6 Internal nodes

So total nodes in that case 19+6 = 25 nodes.
answered by Veteran (17.1k points)  
selected by
+1 vote
As there is a formulae regarding this:


where I=number of internal nodes

L=number of leaf nodes

n=n-ary tree

so in this ques, L=20


I=6.33 can be approximated to 7

now asking for total number of nodes so 20+7

thats 27 nodes
answered by Loyal (3.3k points)  
edited by
@kirti plz verify ur formula.

I & L should be swapped in ur formula.
yep.. thats my mistake.. it should be L=I(n-1)+1

and then acc to that, ur answer is right.. thanku for correcting me..
You are welcome.
0 votes
The total number of nodes = number of Internal nodes (I) + number of leaf nodes (L)

number of leaf nodes (L)=20

number of Internal nodes (I) = [( L-1)/(n-1)] where n = n-ary tree here n=4

I= [(20-1)/(4-1)], so I=6

total number of nodes = 20+6=26
answered by Junior (531 points)  

Top Users Jul 2017
  1. Bikram

    4386 Points

  2. manu00x

    2464 Points

  3. Debashish Deka

    1850 Points

  4. joshi_nitish

    1686 Points

  5. Arjun

    1340 Points

  6. Hemant Parihar

    1184 Points

  7. Arnab Bhadra

    1112 Points

  8. Shubhanshu

    1080 Points

  9. Ahwan

    900 Points

  10. rahul sharma 5

    732 Points

24,031 questions
30,983 answers
29,358 users