Data Structures & AlgorithmsHardProduct-company MCQ pattern

Keys 1, 2, 3, 4, 5, 6, 7 are inserted in that order into an empty AVL tree. How many rotations (counting a double rotation as one rebalancing) are performed, and what is the level order of the final tree?

  1. A. 4 rebalancings; 4 2 6 1 3 5 7
  2. B. 6 rebalancings; 4 2 6 1 3 5 7
  3. C. 4 rebalancings; 2 1 4 3 6 5 7
  4. D. 3 rebalancings; 4 2 6 1 3 5 7

Correct answer: A. 4 rebalancings; 4 2 6 1 3 5 7

Single left rotations happen after inserting 3 (at 1), 5 (at 3), 6 (at the root 2) and 7 (at 5), four in all, and the tree ends perfectly balanced: level order 4 2 6 1 3 5 7. A plain BST with these inserts would be a chain of height 6.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic