Data Structures & AlgorithmsHardProduct-company placement

Keys 90, 39, 48, 71, 49, 22, 33, 44, 15 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?

  1. A. 48, 39, 22, 15, 33, 44, 71, 49, 90
  2. B. 90, 39, 22, 15, 33, 48, 44, 71, 49
  3. C. 48, 33, 22, 15, 39, 44, 71, 49, 90
  4. D. 15, 22, 44, 39, 33, 49, 90, 71, 48

Correct answer: C. 48, 33, 22, 15, 39, 44, 71, 49, 90

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