ITPEC FE Morning October 2022 Question 4

Source exam: ITPEC FE Morning October 2022Topic: Basic Theory & Math

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
  • + → pop 2 and 12 + 1 = 3 → push 3
  • - → pop 9 and 39 - 3 = 6 → push 6
  • Push 3
  • × → pop 6 and 36 × 3 = 18 → push 18

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.