ITPEC FE Morning October 2019 Question 5

What is the result after evaluation of the following postfix expression? Here, symbols +, −, ×, and ÷ represent the arithmetic operators of addition, subtraction, multiplication, and division, respectively.

5 4 6 + × 4 9 3 ÷ + ×

Explanation

350 — evaluate the postfix expression with a stack: push each number, and let each operator pop two values and push the result.

  • •push 5, 4, 6; apply + → 4 + 6 = 10, stack 5, 10
  • •apply × → 5 × 10 = 50, stack 50
  • •push 4, 9, 3; apply ÷ → 9 ÷ 3 = 3, stack 50, 4, 3
  • •apply + → 4 + 3 = 7, stack 50, 7
  • •apply × → 50 × 7 = 350

In infix form this is 5 × (4 + 6) × (4 + 9 ÷ 3) = 50 × 7 = 350.

Answer (d)

Why not others:

  • •(a) 98, (b) 154 and (c) 238 — these are 14 × 7, 22 × 7 and 34 × 7: the second half is right, but the first half is not 50. The first operator, +, takes the two values on top, 4 and 6, and the × after it multiplies that sum by 5, so the first half can only be 5 × 10 = 50

Key rule: In postfix, each operator applies to the two most recent values on the stack, and the value popped second is the left operand, which matters for − and ÷.

Basic Theory · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.