The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+14 votes
1.3k views

The inorder and preorder 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 postorder traversal of the binary tree is:

  1. $\text{d e b f g c a}$

  2. $\text{e d b g f c a}$

  3. $\text{e d b f g c a}$

  4. $\text{d e f g b c a}$

asked in DS by Veteran (59.6k points)
retagged by | 1.3k views

2 Answers

+18 votes
Best answer

The answer is A.

Take the first node in preorder traversal - a will be the root of the tree
All nodes to the left of '$a$' in inorder traversal will be in the left subtree of '$a$' and all elements on the right will be in the right subtree of '$a$'. 
Take the second element from preorder traversal - '$b$' - goes to left subtree of '$a$' as it is in the left of '$a$' in inorder list. 
Proceeding likewise we can construct the binary tree as:

answered by Boss (19.7k points)
edited by
+1 vote
Firstly we have to find Binary tree from inorder and preorder then we can find postorder

debfgca option A is right
answered by Loyal (6.9k points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

40,992 questions
47,620 answers
146,894 comments
62,346 users