in DS
632 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.

in DS
by
632 views

1 Answer

2 votes
2 votes
Best answer

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

2 Comments

I looked the answer key from where I got this question, it says AB+CD*E-FG/**

I am confused, which is correct. Ours or their answer 😅

0
0
Yours and my answer is 100% correct.
1
1