GATE / CS ARCHIVE

GATE CSE 2026 SET 1 / QUESTION 62

Reconstructing a BST from preorder

Data Structures · Binary Search & Balanced Trees · Full GATE CSE 2026 Set 1 paper

GATE 2026 Set 1, Q62 2 marks · NAT
Report issue

Binary Search & Balanced Trees

Question 62, GATE 2026: A binary search tree has preorder sequence 50,25,13,40,30,47,75,60,70,80,77. Find the 1-based position of 60 in its postorder traversal.
Tap to enlarge
Answer & solution

Official answer: 7

Step through it (25 steps)

Givens and goal

A binary search tree has preorder sequence 50,25,13,40,30,47,75,60,70,80,77. Find the 1-based position of 60 in its postorder traversal.

Approach

Recursively split the preorder at each root according to BST value bounds, then traverse left, right, root.

Step-by-step solution

1. The first preorder entry is root 50. The following values below 50 form its left subtree: 25,13,40,30,47. The rest form its right subtree: 75,60,70,80,77.
2. In the left subtree, 25 has left child 13 and right subtree rooted at 40, whose children are 30 and 47. Its postorder is therefore 13,30,47,40,25.
3. In the right subtree, root 75 has a left subtree rooted at 60, containing 70 as 60’s right child. Its right subtree is rooted at 80, with left child 77. Thus that subtree’s postorder is 70,60,77,80,75.
4. The reconstructed tree is:

              50
          /        \
        25          75
       /  \        /  \
     13   40      60   80
         /  \      \  /
        30  47     70 77

5. Concatenate left-subtree postorder, right-subtree postorder and root: 13,30,47,40,25,70,60,77,80,75,50. The first five positions belong to the left subtree, position 6 is 70 and position 7 is 60.
6. Therefore the answer is 7. Preorder visits root first, while postorder visits root last; simply looking up 60’s original preorder position would answer the wrong traversal question.

Original paper, page 45 · Answer key