GateAI
Binary Search Trees

GATE CSE 2017 Set 2 · Q36

MCQ2 marksMedium

Time

The pre-order traversal of a binary search tree is given by 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20. Then the post-order traversal of this tree is:

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

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

Binary Search Trees

For a Binary Search Tree (BST), the in-order traversal is always in ascending sorted order.

Given the pre-order traversal: Pre-order: 12,8,6,2,7,9,10,16,15,19,17,2012, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20

Sorting the elements gives the in-order traversal: In-order: 2,6,7,8,9,10,12,15,16,17,19,202, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19, 20

  1. The root of the tree is the first element of the pre-order traversal: 12.

  2. In the in-order traversal, elements to the left of 1212 are {2,6,7,8,9,10}\{2, 6, 7, 8, 9, 10\} (Left Subtree) and to the right are {15,16,17,19,20}\{15, 16, 17, 19, 20\} (Right Subtree).

  3. Reconstructing the Left Subtree (Root = 88):

    • Left of 88: {2,6,7}\{2, 6, 7\} (Pre-order: 6,2,76, 2, 7; Root = 66, Left child = 22, Right child = 77). Post-order: 2,7,62, 7, 6.

    • Right of 88: {9,10}\{9, 10\} (Pre-order: 9,109, 10; Root = 99, Right child = 1010). Post-order: 10,910, 9.

    • Post-order of left subtree: 2,7,6,10,9,82, 7, 6, 10, 9, 8.

  4. Reconstructing the Right Subtree (Root = 1616):

    • Left of 1616: {15}\{15\}. Post-order: 1515.

    • Right of 1616: {17,19,20}\{17, 19, 20\} (Pre-order: 19,17,2019, 17, 20; Root = 1919, Left child = 1717, Right child = 2020). Post-order: 17,20,1917, 20, 19.

    • Post-order of right subtree: 15,17,20,19,1615, 17, 20, 19, 16.

Combining Left Subtree, Right Subtree, and Root gives the overall post-order traversal: 2,7,6,10,9,8,15,17,20,19,16,122, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12.

Therefore, option B is correct.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Binary Search Trees previous year question is Q36 of the GATE CSE 2017 Set 2 paper. Find more GATE CSE PYQs on Binary Search Trees in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Binary Search Trees PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Binary Search Trees in GATE CSE

Binary Search Trees has 21 GATE CSE PYQs across 17 papers from 2011 to 2026. 6 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2017 Set 2.

How GATE tests Binary Search Trees

More from GATE CSE 2017 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 2 · Q36 · MCQ

The pre-order traversal of a binary search tree is given by 12, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20. Then the post-order traversal of this tree is:

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.