Data Structures & AlgorithmsHardProduct-company placement

Keys 85, 36, 65, 27, 34, 80, 17, 66, 97, 68 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. 3 rotations, root 65
  2. B. 5 rotations, root 85
  3. C. 5 rotations, root 65
  4. D. 6 rotations, root 65

Correct answer: C. 5 rotations, root 65

The rebalancing events are LR at 85, LR at 36, LL at 85: 1 single and 2 double, i.e. 1 + 2×2 = 5 rotations; the root ends as 65.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic