• edited by
1,909 views
3 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}$

2 Answers

Best answer
5 5 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:
Position:
Show:

Related questions

2 2 votes
5 answers 5 answers
2.8k
2.8k views
gatecse asked Dec 17, 2017
2,840 views
A strictly binary tree with $10$ leavescannot have more than $19$ nodeshas exactly $19$ nodeshas exactly $17$ nodeshas exactly $20$ nodes
7 7 votes
2 answers 2 answers
4.1k
4.1k views
gatecse asked Dec 17, 2017
4,085 views
The number of structurally different possible binary trees with $4$ nodes is $14$$12$$336$$168$
3 3 votes
2 2 answers
4.5k
4.5k views
gatecse asked Dec 17, 2017
4,492 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...
1 1 vote
1 1 answer
1.3k
1.3k views
gatecse asked Dec 17, 2017
1,331 views
The minimum number of stacks needed to implement a queue is$3$$1$$2$$4$