in DS edited by
6,754 views
21 votes
21 votes

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
in DS edited by
6.8k views

3 Answers

41 votes
41 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.

edited by

1 comment

Adding little bit more to answer:-

For inorder:- left->root->right

For preorder:-root->left->right

Therefore for perorder and inorder the ending are same but it is for somecases
0
0
8 votes
8 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

7 votes
7 votes
Answer: D

Binary Tree is:

    K                          
   /   \                          
  A    Y  
 /   \     \   
M  C    P           
     /     /  \
   B     F  H
Answer:

Related questions