GATE CSE
First time here? Checkout the FAQ!
x
+5 votes
527 views

The following three are known to be the preorder, inorder and postorder sequences of a binary tree. But it is not known which is which.

  1. MBCAFHPYK
  2. KAMCBYPFH
  3. MABCKYFPH

Pick the true statement from the following.

  1. I and II are preorder and inorder sequences, respectively
  2. I and III are preorder and postorder sequences, respectively
  3. II is the inorder sequence, but nothing more can be said about the other two sequences
  4. II and III are the preorder and inorder sequences, respectively
asked in DS by Veteran (20.8k points)  
retagged by | 527 views

4 Answers

+16 votes
Best answer
In preorder, root comes at the beginning of the traversal sequence and in postorder, root comes at the last of the traversal sequence. So, out of the given sequences only 1 and 2 are having such kind of order i.e K at the beginning and at the last.

Therefore, 2 is the preorder and 1 is postorder and the left sequence i.e 3 will definitely be inorder.

So, option d is correct.
answered by Active (2.3k points)  
selected by
+6 votes
Answer: D

Binary Tree is:

    K                          
   /   \                          
  A    Y  
 /   \     \   
M  C    P           
     /     /  \
   B     F  H
answered by Veteran (35.1k points)  
+3 votes

 

Using this as preorder KAMCBYPFH and inorder MABCKYFPH .

So this gives II and III are the preorder and inorder sequences, respectively.

Ans is option D

answered by Veteran (49.2k points)  
+2 votes
option D)
answered by Junior (873 points)  


Top Users Sep 2017
  1. Habibkhan

    7142 Points

  2. Warrior

    2640 Points

  3. Arjun

    2480 Points

  4. rishu_darkshadow

    2466 Points

  5. A_i_$_h

    2214 Points

  6. nikunj

    1980 Points

  7. manu00x

    1846 Points

  8. makhdoom ghaya

    1770 Points

  9. Bikram

    1744 Points

  10. SiddharthMahapatra

    1718 Points


26,133 questions
33,705 answers
79,886 comments
31,105 users