Data Structures & AlgorithmsHardProduct company OA · Infosys pattern

Keys 10, 20, 30, 25, 28 are inserted into an empty AVL tree. Which rotations are performed, in order (named by imbalance case)?

  1. A. RR, LR → root 20
  2. B. RR, RL → root 20
  3. C. RR, RR → root 25
  4. D. RL, LR → root 28

Correct answer: A. RR, LR → root 20

10, 20, 30 is right-right → left rotation at 10, root 20. 25 goes under 30 on the left, then 28 goes to 25's right: 30 now has balance +2 with a left child that is right-heavy → LR case (left rotation at 25, right rotation at 30), giving 28 with children 25 and 30. The root stays 20. The imbalance at 30 leans LEFT, so RL is the wrong case.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic