Data Structures & AlgorithmsVery hardGATE CS · Infosys Mysore

Distinct keys are inserted one by one, in the order 39 78 13 28 97 77 80 44 53 61 91 64, 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. 39 78 97 80 91 77 44 53 61 64 13 28
  2. B. 28 13 64 61 53 44 77 91 80 97 78 39
  3. C. 39 13 78 28 77 97 44 80 53 91 61 64
  4. D. 39 13 28 78 77 44 53 61 64 97 80 91

Correct answer: D. 39 13 28 78 77 44 53 61 64 97 80 91

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