635 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
retagged | 635 views

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.
selected

Binary Tree is:

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

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

option D)