Skip to content

ISRO Scientist/Engineer CSE 2018Data Structures › Binary Trees and Binary Search Trees

ISRO Scientist/Engineer CSE 2018 PYQ: If $\text{Tree-1}$ and $\text{Tree-2}$ are the trees indicated below: Which traversals of $\text{Tree-1}$…

If $\text{Tree-1}$ and $\text{Tree-2}$ are the trees indicated below:

Which traversals of $\text{Tree-1}$ and $\text{Tree-2}$, respectively, will produce the same sequence?

  1. A
    Preorder, postorder
  2. B
    Postorder, inorder
    Correct answer
  3. C
    Postorder, preorder
  4. D
    Inorder, preorder

Answer

(B) Postorder, inorder

Approach

Tree-1 is A - B - D - E with children G,H (H->I->J) and F, plus A's right child C. Its postorder is G, J, I, H, E, F, D, B, C, A. Tree-2 is rooted at G (with F as its right child), F has E (with I -> J,H) and C (with A and a sub-chain containing B and D). Its inorder is G, J, I, H, E, F, D, B, C, A - the same sequence as Tree-1's postorder. Hence option B (postorder of Tree-1, inorder of Tree-2) is the intended answer. No other pair matches: Tree-1 preorder = A B D E G H I J F C while Tree-2 postorder = J H I E B D A C F G (option A fails); Tree-1 postorder = G J I H E F D B C A while Tree-2 preorder = G F E I J H C D B A (option C fails immediately, since the second symbol differs J vs F); Tree-1 inorder = B G E J I H D F A C vs Tree-2 preorder = G F E I J H C D B A (option D fails). Note the figure contains a tiny drawing slip in the B/D chain of Tree-2 (the two labels come out interchanged in a literal reading), which is why several solvers saw a mismatch; the intended pair is unambiguously postorder/inorder.

Reviewed by ISRO IQ Editorial Team.