ITPEC FE Subject A April 2024 Question 3

Source exam: ITPEC FE Subject A April 2024Topic: Basic Theory & Math

ITPEC FE Subject A April 2024 — Question 3 of 60

Postfix (Reverse Polish) Notation — evaluate an expression using a stack.

Expression: 100 5 6 2 + * 12 4 / - - 36 -

Step-by-step stack evaluation:

  • 100[100]
  • 5[100, 5]
  • 6 2 + → 6+2 = 8[100, 5, 8]
  • * → 5×8 = 40[100, 40]
  • 12 4 / → 12÷4 = 3[100, 40, 3]
  • - → 40−3 = 37[100, 37]
  • - → 100−37 = 63[63]
  • 36[63, 36]
  • - → 63−36 = 27

Why not others:
- (a) 5 — incorrect operator ordering

- (b) 18 — likely error in subtraction order

- (c) 21 — arithmetic mistake

Key rule: When an operator is encountered, pop two operands: the first popped is the right operand, the second popped is the left. For - and /, order matters: left - right, left / right.

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.