1,090 views
0 votes
0 votes

According to my knowledge, it should be AB+CD*E-*F*G/

And, here is the step-wise explanation of it

  1. Converting the bracket of (A+B) – AB+
  2. There is operator but the next operand is entire bracket term, it has to be first evaluated (C*D – E) – CD*E-
  3. Multiply it with the evaluated expression in step 1 – AB+CD*E-*
  4. There is operator with F operand to right and evaluated expression in step 3 – AB+CD*E-*F*
  5. Now we have divide operator with G operand on right and evaluated expression in step 4 – AB+CD*E-*F*G/

Please confirm if my logic and answer is correct or not.

Note Mind the space around / operator. It is there on purpose.

1 Answer

Best answer
2 votes
2 votes

It’s easy, just go from left to right, convert the highest precedence operator first then treat the converted one as a single operand, and repeat until it’s fully converted. You must have knowledge of the Precedence Table Before using this method.

Example – (A+B)*(C*D-E)*F/G

Step 1 – Move L to R Find the highest precedence i.e,  (A+B) convert it to AB+, and treat AB+ as a single operand from now on

Step 2 – AB+ *(C*D-E)*F/G   Now the next highest is (C*D-E) convert it to CD*E-

Step 3- AB+ * CD*E- *F/G  Move L to R Tiebreaker between *, * and / is Associativity so convert with first occurred * – AB+CD*E-* *F/G 

Step 4 –   AB+CD*E-* *F/G  L to R again tie go for * bcoz of associativity AB+CD*E-*F* /G 

Step 5 – Now only one operator left so convert it to AB+CD*E-*F*G/

Your answer is correct but the logic is not properly stated. 

selected by

Related questions

2 votes
2 votes
2 answers
1
Amit puri asked Sep 29, 2016
2,774 views
Convert the infix to postfix and prefix expression1) log3! ^log4 *log log 6/7*4!2)log3!^sin 2*cos 3
1 votes
1 votes
1 answer
2
0 votes
0 votes
0 answers
3
Mk Utkarsh asked Oct 20, 2018
860 views
Please convert it to postfix by using stack and explain in detailvoid (*bsd_signal(int sig, void (*func)(int)))(int);
2 votes
2 votes
1 answer
4
Himanshu Goyal asked Jul 14, 2017
5,577 views
How is ans 15 for this question Please can anybody solve this