Homeβ€ΊStudy Resourcesβ€ΊComputer Scienceβ€Ί
What is Reverse Polish notation?
Computer Science
A-Level

What is Reverse Polish notation?

Reverse Polish notation (RPN) is a postfix way of writing expressions, where each operator comes after its operands. It needs no brackets, and a stack can evaluate it. In AQA A Level Computer Science (7517), you convert simple infix expressions to RPN and back again. Example: Convert (3 + 4) Γ— 5 to RPN. Write 3 + 4 first as 3 4 +, then apply Γ— 5. Answer: 3 4 + 5 Γ—, which evaluates to 35.

Quick answer: What is Reverse Polish notation? Reverse Polish notation (RPN) is a postfix notation in which every operator is written after its operands, so (3 + 4) Γ— 5 becomes 3 4 + 5 Γ—. It removes the need for brackets and suits stack-based evaluation. This page covers A Level Computer Science, AQA (7517). It is A level only content.

Key terms

  • Infix: the operator sits between operands, as in 3 + 4.
  • Postfix (RPN): the operator follows its operands, as in 3 4 +.
  • Precedence: brackets first, then Γ— and Γ·, then + and βˆ’.
  • Stack rule: push numbers; at an operator, pop two values, apply it and push the result. The first value popped is the right-hand operand.

Extra example

Evaluate 5 1 2 + 4 Γ— + 3 βˆ’ using a stack.

  1. Push 5, 1 and 2. Stack: 5, 1, 2.
  2. + pops 2 and 1 and pushes 3. Stack: 5, 3.
  3. Push 4. Γ— pops 4 and 3 and pushes 12. Stack: 5, 12.
  4. + pops 12 and 5 and pushes 17. Stack: 17.
  5. Push 3. βˆ’ pops 3 and 17 and pushes 17 βˆ’ 3 = 14.

Answer: 14. The infix form is 5 + (1 + 2) Γ— 4 βˆ’ 3 = 14.

Extra example

Convert a + b Γ— c to RPN.

  1. Γ— has higher precedence than +, so b Γ— c is done first: b c Γ—.
  2. Treat (b c Γ—) as one operand of +.
  3. Write a, then b c Γ—, then +.

Answer: a b c Γ— +

Want one-to-one help? Find an online Computer Science tutor with ExpertTutor.

Reviewed by

Want one-to-one support?

One-to-one online tuition can help you build confidence in your subject. Find a tutor who teaches your course.

Find a Tutor

Learn face to face in Glasgow

Prefer in-person lessons? Visit the ExpertTutor Glasgow Southside centre.

See the centre