The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is:
(A)
n/2
(B)
(n-1)/3
(C)
(n-1)/2
(D)
(2n+1)/3
Answer: (D)
Explanation:
In a tree with nodes, some having 0 or 3 children:
Let’s call:
n – as the total number of nodes.
L -the number of leaf nodes.
I – as the number of internal nodes.
Now, here’s the deal: each internal node with 3 children gives us 2 internal nodes and 1 leaf node. The root node doesn’t play a role here, so we can say (L = 2I + 1).
And we know that the total number of nodes n is just the sum of leaf nodes L and internal nodes I: n = L + I
Now, if we substitute the L value from the first equation into the second one, we get n = (2I + 1) + I, which simplifies to n = 3I + 1.
Solving this for I, we find I = (n-1)/3
Now, plug this back into the L equation, and we get L = 2((n-1)/3) + 1, which simplifies to L = (2n+1)/3.
So, in simple terms, the number of leaf nodes L in a tree with nodes having 0 or 3 children is (2n+1)/3.
Quiz of this Question
Please comment below if you find anything wrong in the above post