What is the correct postfix (Reverse Polish) expression for the infix…
2024
What is the correct postfix (Reverse Polish) expression for the infix expression (a+b)*(c-d) ?
- A.
(a+b)*(c-d)
- B.
ab+cd-*
- C.
+ab-cd*
- D.
abcd+*-
- E.
ab+*cd-
Attempted by 66 students.
Show answer & explanation
Correct answer: B
We convert the infix expression (a+b)*(c-d) to postfix using the standard stack-based (Shunting-Yard) method, where every operator is written immediately after its two operands.
Step 1 - inner expressions first. The two parenthesised groups are evaluated before the outer operator: (a+b) becomes ab+ and (c-d) becomes cd-.
Step 2 - apply the outer operator. The multiplication * acts on the two results ab+ and cd-, and in postfix the operator comes last: ab+ cd- * = ab+cd-*.
Therefore the correct postfix form is ab+cd-* (option b).
Check by evaluation: push a, b, do a+b; push c, d, do c-d; then * multiplies the two, reproducing (a+b)*(c-d). This confirms the result.