The GATE Grind

GATE 2013 CS (CS1) – Question 53

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

A BST has preorder 30,20,10,15,25,23,39,35,42. Find its postorder.

  1. 10,20,15,23,25,35,42,39,30
  2. 15,10,25,23,20,42,35,39,30
  3. 15,20,10,23,25,42,35,39,30
  4. 15,10,23,25,20,35,42,39,30

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) 15,10,23,25,20,35,42,39,30

Explanation

Root thirty separates left subtree 20,10,15,25,23 and right subtree 39,35,42. Left postorder is 15,10,23,25,20; right postorder is 35,42,39. Append root thirty to obtain D. Each recursive split follows the BST ordering property.

More Trees and Binary Search Trees questions

All Trees and Binary Search Trees questions →