in Programming in C
5,584 views
0 votes
0 votes
The in-order traversal of a tree resulted in FBGADCE. Then pre-order traversal would result in.

a)FGBDECA

b)ABFGCDE

C)BFGCDEA

d)AFGBDEC
in Programming in C
5.6k views

6 Answers

0 votes
0 votes

If we are given preorder and inorder then we can generate a unique binary tree. But in question we are given only in order. 

So, what we do now -  we take inorder & options one by one (as preorder) and try to make unique binary tree from them.

We will observe that options A & C will fail.

Only B & D can generate unique trees. so, options (B) & (D) are correct

Trees will look like this as given by Pranay Datta 1 

x

0 votes
0 votes

Given:

In-order result=FBGADEC,asking for pre order

Sol:

first construct the tree based on in-order result,ie.rule of in order is left-root-right, now you will get the structure of tree, then apply the pre order rule in that tree ie.,root-left-right you wil get the answer is ABFGCDE.so the answer is option (B)