GATE Computer ScienceHardGATE CS (PYQ pattern)

Keys 30, 10, 20, 50, 40, 60, 45 are inserted into an initially empty AVL tree in this order. What are the root and the total number of rotations (a double rotation counts as 2)?

  1. A. root 40, 6 rotations
  2. B. root 30, 5 rotations
  3. C. root 40, 4 rotations
  4. D. root 40, 5 rotations

Correct answer: D. root 40, 5 rotations

Insert 30, 10, 20: left-right double rotation gives root 20. Then 50, 40, 60 and 45 cause further imbalance; simulating gives root 40 and 5 rotations in all.

More Programming and Data Structures (GATE) questions

Exams that ask this topic