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) ?

  1. A.

    (a+b)*(c-d)

  2. B.

    ab+cd-*

  3. C.

    +ab-cd*

  4. D.

    abcd+*-

  5. 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.

Explore the full course: Niacl Ao It Specialist