GATE / CS ARCHIVE

GATE CSE 2004 / QUESTION 35

Traversal pairs uniquely determining a binary tree

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

GATE 2004, Q35 2 marks · MCQ
Report issue

Tree Properties & Traversals

Question 35, GATE 2004: For an unrestricted binary tree with distinct node labels, which pairs of label sequences determine the tree uniquely? (i) preorder and postorder; (ii) inorder and postorder; (iii) preorder and inorder; (iv) level order and postorder.
Options:
(A) i only
(B) ii and iii
(C) iii only
(D) iv only
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. With distinct node labels, inorder plus preorder identifies the root then splits both subtrees recursively; inorder plus postorder does the same using the final element as root. Thus ii and iii, B.

2. A root with one left child versus one right child has identical preorder, postorder and level order, so the other pairs do not suffice for unrestricted binary trees. Distinct labels are the conventional assumption.

3. Teaching check: For a concrete ambiguity, a root A with sole left child B and a root A with sole right child B both have preorder A,B, postorder B,A and level order A,B. Inorder distinguishes B,A from A,B, explaining why it is indispensable among the offered pairs.

Original paper, page 5