Data Structures & AlgorithmsHardGATE CSE · AVL

Keys 10, 20, 30, 40, 50, 25 are inserted in this order into an empty AVL tree. What is the preorder traversal of the final tree?

  1. A. 10 20 30 25 40 50
  2. B. 20 10 30 25 40 50
  3. C. 30 20 10 25 40 50
  4. D. 30 20 10 25 50 40

Correct answer: C. 30 20 10 25 40 50

The 3rd and 5th insertions force left rotations (giving 20 over 10 and 40, with 40 over 30 and 50); inserting 25 unbalances the root in the right-left case, and a double rotation makes 30 the root: 30 (20 (10, 25), 40 (-, 50)).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic