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

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.8k points)
retagged by | 1.5k 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.9k 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 Boss (11k points)

Related questions

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
49,403 questions
53,576 answers
70,852 users