ITPEC FE Morning October 2022 Question 4
ITPEC FE Morning October 2022 — Question 4 of 80
Reverse Polish Notation (RPN) — evaluate a postfix arithmetic expression using a stack.
Expression: 9 2 1 + - 3 ×
Step-by-step using a stack:
- •Push
9,2,1 - •
+→ pop2and1→2 + 1 = 3→ push3 - •
-→ pop9and3→9 - 3 = 6→ push6 - •Push
3 - •
×→ pop6and3→6 × 3 = 18→ push18
Result: 18 → answer is (d)
Why not others:
- (a) 0 — incorrect order of operations
- (b) 4 — likely confused subtraction operand order
- (c) 10 — incorrect grouping of operators
Key rule: In RPN, each operator pops the top two stack values; the second-to-top is the left operand, the top is the right operand. For - and ÷, operand order matters.
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.