Data Structures & AlgorithmsHardGATE CS · Product-company placement

Keys 92, 49, 31, 85, 28, 73, 29, 81, 90 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?

  1. A. 49, 28, 31, 29, 85, 73, 81, 92, 90
  2. B. 92, 49, 31, 28, 29, 85, 73, 81, 90
  3. C. 28, 31, 29, 81, 73, 90, 92, 85, 49
  4. D. 49, 29, 28, 31, 85, 73, 81, 92, 90

Correct answer: D. 49, 29, 28, 31, 85, 73, 81, 92, 90

Rebalance at the lowest unbalanced ancestor after each insert; the rotations performed are LL at 92, LL at 92, LR at 31. 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