Data Structures & AlgorithmsHardProduct-company placement

Keys 37, 84, 56, 34, 79, 18, 83, 69, 74 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?

  1. A. 56, 34, 18, 37, 83, 74, 69, 79, 84
  2. B. 56, 34, 18, 37, 79, 69, 74, 84, 83
  3. C. 37, 34, 18, 84, 56, 79, 69, 74, 83
  4. D. 18, 37, 34, 69, 79, 74, 84, 83, 56

Correct answer: A. 56, 34, 18, 37, 83, 74, 69, 79, 84

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