The GATE Grind

GATE 2017 CS (CS2) – Question 46

Programming and Data Structures · Trees and Binary Search Trees · 2 marks · Multiple choice

BST preorder is 12,8,6,2,7,9,10,16,15,19,17,20. Find its postorder.

  1. 2,6,7,8,9,10,12,15,16,17,19,20
  2. 2,7,6,10,9,8,15,17,20,19,16,12
  3. 7,2,6,8,9,10,20,17,19,15,16,12
  4. 7,6,2,10,9,8,15,16,17,20,19,12

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 2,7,6,10,9,8,15,17,20,19,16,12

Explanation

Root 12 splits left keys below 12 from right keys above 12. The left subtree rooted at 8 has postorder 2,7,6,10,9,8. The right rooted at 16 has 15,17,20,19,16. Appending root 12 gives option B. Every subtree follows left, right, root.

More Trees and Binary Search Trees questions

All Trees and Binary Search Trees questions →