Saltar al contenido

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.

18 levelsFree bench

In the exam

Exam questions on what this lab teaches, with the points that gain marks.

9618/31 May/June 2024 · Question 59 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

  1. (a) One mark each for (5 + 2), then / (9 – 3), then * 3: ((5 + 2) / (9 - 3)) * 3.
  2. (b) One mark for 7 3 +, one for 2 8 * - 6 /: 7 3 + 2 8 * - 6 /.
  3. (c) One mark for each stack state: 17 and 5 pushed, then 12 (17 - 5).
  4. 7 and 3 pushed on top of 12, then 10 (7 + 3).
  5. 12 * 10 = 120.
  6. 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.

9618/31 May/June 2026 · Question 79 marks

(a) Write 21 * (15 – 3 + 8) / 7 in RPN. (b) Write c d + a b – a c – * / in infix form. (c) Show the changing contents of the stack as 15 9 – 24 3 / * 18 6 + / is evaluated.

Points that gain marks

  1. (a) 21 15 3 – 8 + * 7 /
  2. (b) (c + d) / ((a – b) * (a – c))
  3. (c) The stack holds 6, then 6 8, then 48; then 48 24; the final total is 2.

In this lab: Levels 'June 2026: to RPN', 'June 2026: to infix' and 'June 2026: evaluate'.

9618/33 May/June 2026 · Question 79 marks

(a) Outline the process of using a stack to evaluate an RPN expression. (b) Write ((18 – 15 + 3) * 5) / 12 in RPN. (c) Show the changing contents of the stack as 16 3 * 36 6 / 18 6 – * + is evaluated.

Points that gain marks

  1. (a) Read the expression from left to right; push each number onto the stack.
  2. (a) For an operator, pop the last two values, apply the operator, and push the result; repeat until the end.
  3. (b) 18 15 – 3 + 5 * 12 /
  4. (c) 48, then 48 6, then 48 6 12, then 48 72, and finally 120.

In this lab: Levels 'June 2026: brackets in brackets' and 'June 2026: a tall stack'.

The question as printed in the exam paper

More real experiments

All labs →

Iniciar sesión o crear cuenta

IGCSE, A-Level & AP