Data Structures & AlgorithmsHardGATE CS · Infosys Mysore

Distinct keys are inserted one by one, in the order 97 11 93 94 45 38 51 83, 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 11 93 94 45 51 83 38
  2. B. 38 83 51 45 94 93 11 97
  3. C. 97 11 93 45 38 51 83 94
  4. D. 97 11 93 45 94 38 51 83

Correct answer: C. 97 11 93 45 38 51 83 94

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