Skip to content

Labs · 9618 A2 16.2

Reverse Polish

Work out expressions the way a computer does: with a stack and no brackets. Turn infix into Reverse Polish notation with an expression tree, and back again.

13 levelsFree bench

In the exam

9618/31 May/June 2024 · Question 5 · 9 marks

(a) Write the RPN 5 2 + 9 3 - / 3 * in infix form. (b) Write the infix expression ((7 + 3) - (2 * 8)) / 6 in RPN. (c) Evaluate the RPN expression a b - c d + * e / when a = 17, b = 5, c = 7, d = 3 and e = 10. Show the changing contents of the stack.

Points that gain marks

  • (a) One mark each for (5 + 2), then / (9 – 3), then * 3: ((5 + 2) / (9 - 3)) * 3.
  • (b) One mark for 7 3 +, one for 2 8 * - 6 /: 7 3 + 2 8 * - 6 /.
  • (c) One mark for each stack state: 17 and 5 pushed, then 12 (17 - 5).
  • 7 and 3 pushed on top of 12, then 10 (7 + 3).
  • 12 * 10 = 120.
  • 10 pushed, then 120 / 10 = 12 is left on the stack.

In this lab: The levels 'From 9618/31 June 2024' are these three parts; the stack is drawn at every step.

More real experiments

Log in or create account

IGCSE, A-Level & AP