GATE / CS ARCHIVE

GATE CSE 2007 / QUESTION 39

Postorder from inorder and preorder

Data Structures · Tree Properties & Traversals · Full GATE CSE 2007 paper

GATE 2007, Q39 2 marks · MCQ
Report issue

Tree Properties & Traversals

Question 39, GATE 2007: A binary tree has inorder traversal d,b,e,a,f,c,g and preorder traversal a,b,d,e,c,f,g. What is its postorder traversal?
Options:
(A) d,e,b,f,g,c,a
(B) e,d,b,g,f,c,a
(C) e,d,b,f,g,c,a
(D) d,e,f,g,b,c,a
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. Approach. The first preorder item is the root. Its position in inorder separates left and right subtrees; recursively repeat, then output left subtree, right subtree, root.

2. Derivation and interpretation. Preorder starts with root a. Inorder splits the left subtree as d,b,e and the right as f,c,g. The remaining preorder makes b the left root with children d,e, and c the right root with children f,g. Postorder is d,e,b,f,g,c,a, option A.

Original paper, page 9