Data Structures & AlgorithmsVery hardGATE CS · Infosys Mysore

Distinct keys are inserted one by one, in the order 97 59 15 80 75 66 23 56 21 36 77, 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. 97 59 80 75 77 66 15 23 56 36 21
  2. B. 21 36 56 23 15 66 77 75 80 59 97
  3. C. 97 59 15 23 21 56 36 80 75 66 77
  4. D. 97 59 15 80 23 75 21 56 66 77 36

Correct answer: C. 97 59 15 23 21 56 36 80 75 66 77

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