GATE | Gate IT 2005 | Question 50
In a binary tree, for every node the difference between the number of nodes in the left and right subtrees is at most 2. If the height of the tree is h > 0, then the minimum number of nodes in the tree is:
(A) 2h – 1
(B) 2h – 1 + 1
(C) 2h – 1
Let there be n(h) nodes at height h. In a perfect tree where every node has exactly two children, except leaves, following recurrence holds. n(h) = 2*n(h-1) + 1 In given case, the numbers of nodes are two less, therefore n(h) = 2*n(h-1) + 1 - 2 = 2*n(h-1) - 1 Now if try all options, only option (b) satisfies above recurrence. Let us see option (B) n(h) = 2h - 1 + 1 So if we substitute n(h-1) = 2h-2 + 1, we should get n(h) = 2h-1 + 1 n(h) = 2*n(h-1) - 1 = 2*(2h-2 + 1) -1 = 2h-1 + 1.
My Personal Notes arrow_drop_up
Please Login to comment...