in DS edited by
2,891 views
4 votes
4 votes

Convert the pre-fix expression to in-fix $- ^{\ast} +ABC^{\ast} – DE+FG$

  1. $(A-B)^{\ast}C+(D^{\ast}E)-(F+G)$
  2. $(A+B)^{\ast}C-(D-E)^{\ast}(F+G)$
  3. $(A+B-C)^{\ast}(D-E)^{\ast}(F+G)$
  4. $(A+B)^{\ast}C-(D^{\ast}E)-(F+G)$
in DS edited by
by
2.9k views

3 Comments

Option b is correct
0
0
There was a typo in the official question paper for option B which is fixed now.
0
0
From right to left scan –

$- * + ABC * -DE \overbrace{+FG}$

$- * + ABC * –DE \overbrace{(F+G)}$

$- * + ABC * \overbrace{(D-E)} \overbrace{(F+G)}$

$- * + ABC  \overbrace{(D-E)*(F+G)}$

$- * \overbrace{(A+B)}C  \overbrace{(D-E)*(F+G)}$

$-  \overbrace{(A+B)*C}  \overbrace{(D-E)*(F+G)}$

$ \overbrace{(A+B)*C-(D-E)*(F+G)}$
1
1

3 Answers

5 votes
5 votes
$\underline{\textbf{Answer:}\Rightarrow}\;\text{Option B}$

$\mathbf{((A+B)*C)-((D-E)*(F+G)))}$
edited by
by
0 votes
0 votes

Infix should be: (((A+B)*C)-((D-E)*(F+G)))

I have tried it here: 

https://ide.geeksforgeeks.org/0C6l9aF7gd 

 

Code source: https://www.geeksforgeeks.org/prefix-infix-conversion/ 

edited by

1 comment

How to calculate infix here ??

what I did was - reverse the expression, so it becomes postfix expression and then evaluate the postfix expression, thus we'll get a tree.

Now do a Inorder traversal on that tree to get Infix expression.

likewise I'm getting - [(G+F) * (E-D)] - [C * (B+A)]

0
0
0 votes
0 votes
Just scan the operands from right to left and try to keep inside parantheses and update the parentheses as per requirement .

Step1 : (F+G)

Step2:(D-E) (F+G)

Step3:((D-E)*(F+G))

Step4:(skip C for now as we don't get any operator for the consecutive operands i.e. for BC)

Final Step:((A+B)*C)-((D-E)*(F+G))

Hence , Option B is correct.
Answer:

Related questions