Data Structures & AlgorithmsHardGATE CS · Product-company placement

The keys [29, 53, 76, 4, 31, 57, 23, 22, 69, 99] are inserted, in this order, into an initially empty binary search tree. What is the preorder traversal (visit root, then left subtree, then right subtree) of the resulting tree?

  1. A. 29 4 53 23 31 76 22 57 99 69
  2. B. 22 23 4 31 69 57 99 76 53 29
  3. C. 4 22 23 29 31 53 57 69 76 99
  4. D. 29 4 23 22 53 31 76 57 69 99

Correct answer: D. 29 4 23 22 53 31 76 57 69 99

Preorder lists the root first and then recurses on the left and right subtrees. The BST shape is set by the insertion order, so sorting the keys or reading them level by level gives a different sequence.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic