GATE Computer ScienceHardGATE CS (PYQ pattern)

Keys 1, 2, 3, ..., 20 are inserted in increasing order into an initially empty AVL tree. What is the key at the root, and how many (single) rotations occurred in total?

  1. A. key 8, 17 rotations
  2. B. key 9, 15 rotations
  3. C. key 8, 15 rotations
  4. D. key 4, 14 rotations

Correct answer: C. key 8, 15 rotations

Ascending insertion only ever needs left (RR) rotations, and the tree keeps re-balancing towards a complete shape. Simulating the 20 insertions gives root 8 and 15 rotations.

More Programming and Data Structures (GATE) questions

Exams that ask this topic