Data Structures & AlgorithmsModerateProduct-company MCQ pattern

The preorder traversal of a BST is 8, 5, 1, 7, 10, 12. What is its postorder traversal?

  1. A. 1 7 5 10 12 8
  2. B. 12 10 7 1 5 8
  3. C. 1 5 7 8 10 12
  4. D. 1 7 5 12 10 8

Correct answer: D. 1 7 5 12 10 8

8 is the root; 5, 1, 7 (smaller) form the left subtree with root 5 and children 1, 7; 10, 12 form the right subtree with 12 as 10's right child. Postorder: 1 7 5, then 12 10, then 8. 1 7 5 10 12 8 puts 10 before its own child.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic