Data Structures & AlgorithmsVery hardGATE CS · Infosys Mysore

Distinct keys are inserted one by one, in the order 11 14 77 49 19 68 86 32 78 52 28, into an empty binary search tree (a smaller key goes to the left, a larger key to the right). What is the preorder traversal of the resulting tree?

  1. A. 11 14 77 86 78 49 68 52 19 32 28
  2. B. 28 32 19 52 68 49 78 86 77 14 11
  3. C. 11 14 77 49 86 19 68 78 32 52 28
  4. D. 11 14 77 49 19 32 28 68 52 86 78

Correct answer: D. 11 14 77 49 19 32 28 68 52 86 78

Each insertion walks down from the root by comparing with the current node, so the first key is the root. Preorder then prints root, left subtree, right subtree; the mirror-image rule of putting larger keys left is a common slip.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic