Data Structures & AlgorithmsHardProduct-company placement

A binary search tree holds exactly the keys 20, 26, 28, 45, 49, 87, 91, 92. Which ONE of the following sequences can be its PREORDER traversal?

  1. A. 91, 26, 20, 49, 45, 28, 92, 87
  2. B. 91, 26, 20, 49, 45, 28, 87, 92
  3. C. 91, 26, 20, 45, 49, 28, 87, 92
  4. D. 91, 26, 92, 49, 45, 28, 87, 20

Correct answer: B. 91, 26, 20, 49, 45, 28, 87, 92

In a valid BST preorder, once a key larger than some node appears (we have moved into that node's right subtree), no later key may be smaller than that node. 91, 26, 20, 49, 45, 28, 87, 92 never breaks this; each other option does at some point.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic