Data Structures & AlgorithmsVery hardGATE CS (PYQ pattern)

Keys 40, 20, 10, 25, 30, 22, 50, 35, 45, 60, 55, 65 are inserted one by one into an initially empty AVL tree. The pre-order traversal of the final tree is:

  1. A. 40 20 10 25 22 30 35 50 45 60 55 65
  2. B. 40 25 20 10 22 35 30 50 45 60 55 65
  3. C. 40 22 20 10 25 35 30 50 45 60 55 65
  4. D. 40 25 20 10 22 30 35 50 45 60 55 65

Correct answer: D. 40 25 20 10 22 30 35 50 45 60 55 65

Rotations occur on inserting 10 (LL), 30 (LR at 40), 22 (RL at 20), 50 (RR at 30) and 55 (RL at 25), which makes 40 the root with 25 and 50 as children. The first option is the unbalanced plain BST order.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic