Data Structures & AlgorithmsHardGATE CS · Product-company placement

Keys 60, 41, 30, 69, 50, 54, 52, 55, 21 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?

  1. A. 54, 41, 30, 21, 50, 52, 60, 55, 69
  2. B. 60, 41, 30, 21, 50, 54, 52, 55, 69
  3. C. 50, 30, 21, 41, 60, 54, 52, 55, 69
  4. D. 21, 41, 30, 52, 55, 54, 69, 60, 50

Correct answer: C. 50, 30, 21, 41, 60, 54, 52, 55, 69

Rebalance at the lowest unbalanced ancestor after each insert; the rotations performed are LL at 60, RL at 41, LL at 41. Treating an LR/RL case as a single rotation leaves a wrong (still unbalanced) shape.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic