in DS
7,082 views
8 votes
8 votes

If the post order traversal gives ab -cd * + then the label of the nodes 1,2,3.. will be

  1. + , -, *, a,b,c,d
  2. a, -,b,+,c,*,d
  3. a,b,c,d,-,*,+
  4. -,a,b,+,*,c,d
in DS
by
7.1k views

3 Answers

13 votes
13 votes
Best answer

PostOrder Traversal of the given tree gives the output: 4 5 2 6 7 3 1.

Comparing the output with a b - c d * + , and making one-to-one correspondence with 4 5 2 6 7 3 1 , we get



1 $\rightarrow$ +,

2 $\rightarrow$ - ,

3 $\rightarrow$ *,

4 $\rightarrow$ a,

5 $\rightarrow$ b,

6 $\rightarrow$ c,

7 $\rightarrow$ d,
 

which matches with option (A)

edited by

1 comment

The correct infix expression of the given postorder is: $(a-b)+(c*d)$

0
0
0 votes
0 votes
In order will be (a-b)+(c*d)

now draw a traversal tree
1 flag:
✌ Edit necessary (MohitKashyap “It's not a BST you can't predict its Inorder”)
0 votes
0 votes

First we draw a curve around the tree starting at the root, moving along the edges and terminate at the root.

Now for the post order traversing, we list the vertices last time the curve passes.

Here those vertices are in order 4>>5>>2>>6>>7>>3>>1...

Since 4=a, 5=b, 2=-, 6=c, 7=d, 3=*, 1=+

This gives A as the answer...

edited by
Answer: