Data Structures & AlgorithmsHardGATE CS

Keys 72, 29, 21, 18, 28, 16, 23, 33, 25, 67 are inserted in order into an empty AVL tree. Counting a double rotation as two single rotations, how many single rotations are performed in total, and what is the final root?

  1. A. 4 rotations, root 21
  2. B. 6 rotations, root 21
  3. C. 6 rotations, root 72
  4. D. 7 rotations, root 21

Correct answer: B. 6 rotations, root 21

The rebalancing events are LL at 72, LL at 29, LR at 28, LR at 72: 2 single and 2 double, i.e. 2 + 2×2 = 6 rotations; the root ends as 21.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic