UGC-NET Jun 2012 · Asymptotic Analysis & Recurrences

MCQ · 2 marks · Problem PROG-DIVC-0018

The post order traversal of a binary tree is DEBFCA. Find out the pre-order traversal
  1. A
    ABFCDE
  2. B
    ADBFEC
  3. C
    ABDECF
  4. D
    None of the above

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionThe last symbol of a postorder is the root, so A is the root and every preorder must start with A. Check option C against the postorder: preorder ABDECF fits the tree\[A\ \text{with left child }B\ (\text{children }D,E)\ \text{and right child }C\ (\text{left child }F).\]Its postorder is D E B F C A, which matches.(A) ABFCDE: B follows A, so B roots one subtree of A and the other subtree (rooted at C, the node just before A in postorder) holds C, D, E; then the postorder would start with B, F, not D, E — impossible.(B) ADBFEC: D is the first node in postorder, hence a leaf, so B, F, E, C form A's other subtree with root B; the postorder would then end in B A, not C A — impossible.So the preorder among the options is ABDECF.Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com