GATE / CS ARCHIVE

GATE CSE 2009 / QUESTION 37

Maximum AVL height with seven nodes

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2009 paper

GATE 2009, Q37 2 marks · MCQ
Report issue

Binary Search & Balanced Trees

Question 37, GATE 2009: Maximum edge-height of an AVL tree with 7 nodes, with singleton height 0? A 2; B 3; C 4; D 5.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

The minimum-node recurrence for edge height h is N(h)=1+N(h−1)+N(h−2), with N(−1)=0, N(0)=1. Hence N(1)=2, N(2)=4, N(3)=7, N(4)=12. Seven nodes attain height 3 but cannot reach 4, so B.

To make an AVL tree as tall as possible with few nodes, give its two subtrees heights h−1 and h−2. Thus the minimum nodes at height h obey N(h)=1+N(h−1)+N(h−2). Starting with empty height−1 and singleton 0 gives 0, 1, 2, 4, 7, 12. Seven nodes suffice exactly for height 3, but any height 4 tree needs at least 12. This proves both attainability and impossibility, so B.

Original paper, page 9