Data Structures & AlgorithmsHardProduct-company placement

Keys 51, 83, 75, 67, 42, 93, 22, 21, 38, 81 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. 5 rotations, root 75
  2. B. 3 rotations, root 75
  3. C. 5 rotations, root 51
  4. D. 6 rotations, root 75

Correct answer: A. 5 rotations, root 75

The rebalancing events are RL at 51, LL at 42, LR at 51: 1 single and 2 double, i.e. 1 + 2×2 = 5 rotations; the root ends as 75.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic