GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 1.14

AVL ancestors after inserting below g

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

GATE 1996, Q1.14 1 mark · MCQ
Report issue

Binary Search & Balanced Trees

Question 1.14, GATE 1996: In the pictured AVL tree, a has children b,e; b has c,d; c has g; e has f. How many nodes become unbalanced when a new child is attached below g, before rebalancing?
Tap to enlarge
Your answer
Answer & solution

Answer: B: 3 (no official key was published)

The insertion increases the height of the subtree rooted at g by one. That increase propagates through c, b and a. At c, its already taller g side becomes two levels taller than its empty opposite side. The same extra level makes b and then a have height difference two. Node g itself has only one new child, so its balance magnitude is one; e and its descendants are unchanged. Thus c,b,a are the three unbalanced nodes before rotations. Counting after AVL repair would answer a different question.

Original paper, page 2