edited by
1,246 views
3 votes
3 votes

The $in$-$order$ and $pre$-$order$ traversal of a binary tree are $\text{d b e a f c g}$ and $\text{a b d e c f g}$ respectively.The $post$-$order$ traversal of a binary tree is

  1. $\text{e d b g f c a}$
  2. $\text{e d b f g c a }$
  3. $\text{d e b f g c a}$
  4. $\text{d e f g b c a}$
edited by

2 Answers

Best answer
4 votes
4 votes

Traversal means processing each node a tree in some order.

  1. Preorder: Visit node -->  Visit left tree -->   Visit right tree.
  2. In-order: Visit left tree -->    Visit node    -->   Visit right tree.
  3. Post order: Visit left tree -->     Visit right tree   -->  Visit node.

Given that

in-order traversal:  d b e a f c g 
pre-order traversal:   a b d e c f g 
  • As pre order started with a it is the root. Also, the nodes before a in inorder traversal is in left tree, nodes after a is right tree. a is root: { d b e} L | { f c g }R
  • among {d b e} node b comes first in pre-order traversal. hence d and e are children of b. As in inorder traversal  d comes before b, it is the left child and e is right child
  • among {f c g} node  c comes first in pre-order traversal. hence f and g are children of c. As in inorder traversal  f comes before c, it is the left child and g is right child.

Result is

Post order traversal will be 

d e b f g c a

Answer is 3

selected by
Answer:

Related questions

7 votes
7 votes
2 answers
1
gatecse asked Dec 17, 2017
1,961 views
Match the following and choose the correct answer in the order $A, B,C$$\begin{array}{|ll|ll|} \hline \text{A.} & \text{Heap Construction} & \text{p.} & O(n\log n) \\\hli...
40 votes
40 votes
5 answers
2
Kathleen asked Sep 22, 2014
43,539 views
What is the maximum height of any AVL-tree with $7$ nodes? Assume that the height of a tree with a single node is $0$.$2$$3$$4$$5$
3 votes
3 votes
2 answers
3
gatecse asked Dec 17, 2017
3,736 views
Which one of the following property is correct for a red-black tree?Every simple path from anode to a descendant leaf contains the same number of black nodes.If a node is...
2 votes
2 votes
2 answers
4
gatecse asked Dec 17, 2017
1,263 views
A strictly binary tree with $10$ leavescannot have more than $19$ nodeshas exactly $19$ nodeshas exactly $17$ nodeshas exactly $20$ nodes