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.
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.