How are non leaf nodes equal to n-1 where n is the no of leaf nodes
Answers
Answered by
1
Explanation:
The number of leaf nodes for any level in a complete binary tree is given by 2^n where n is the level.
For the last level, the value of n is l where l is the height of the tree.
The total number of nodes in a complete binary tree is given by 1+ 2^1 + 2^2 ….till 2^l.
This summation is given by (2^(l +1)-1)
So the number of non leaf nodes are (2^(l+1)-2^l-1).
Now, given the value of number of non leaf nodes, we can calculate the value of l and hence the total number of nodes in the tree.
Hope it helps. :-)
Similar questions