Data Structures & AlgorithmsModerateProduct-company MCQ pattern

AVL tree: keys 30, 10, 20 are inserted in that order into an empty tree. What rebalancing happens, and what is the root afterwards?

  1. A. Single left rotation; root 20
  2. B. Left-Right double rotation; root 20
  3. C. No rotation is needed; root 30
  4. D. Single right rotation; root 10

Correct answer: B. Left-Right double rotation; root 20

30 becomes unbalanced (balance +2) with the new node in the RIGHT subtree of its LEFT child: the LR case. Rotate 10 left, then 30 right, making 20 the root with children 10 and 30. A single right rotation would leave 10 as root with 20 under 30, still unbalanced.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic