ITPEC FE Morning April 2022 Question 4
ITPEC FE Morning April 2022 — Question 4 of 80
Reverse Polish Notation (RPN) — evaluate and match equivalent postfix expressions.
Given expression: 3 4 − 5 ×
Step-by-step evaluation:
- Push 3, push 4
- −: pop 4 and 3 → 3 − 4 = -1
- Push 5
- ×: pop 5 and -1 → -1 × 5 = -5
Result: -5
Checking each option:
- (a) 3 4 5 × − → 4 × 5 = 20, then 3 − 20 = -17
- (b) 4 5 − 3 × → 4 − 5 = -1, then -1 × 3 = -3
- (c) 5 3 4 − × → 3 − 4 = -1, then 5 × (-1) = -5 ✔
- (d) 5 4 3 − × → 4 − 3 = 1, then 5 × 1 = 5
Key rule: In RPN, operands are pushed onto a stack; when an operator appears, the top two values are popped. For non-commutative operators (−, ÷), the second-popped value is the left operand.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
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.