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.
- Push 5, 1 and 2. Stack: 5, 1, 2.
- + pops 2 and 1 and pushes 3. Stack: 5, 3.
- Push 4. Γ pops 4 and 3 and pushes 12. Stack: 5, 12.
- + pops 12 and 5 and pushes 17. Stack: 17.
- 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.
- Γ has higher precedence than +, so b Γ c is done first: b c Γ.
- Treat (b c Γ) as one operand of +.
- Write a, then b c Γ, then +.
Answer: a b c Γ +
Want one-to-one help? Find an online Computer Science tutor with ExpertTutor.
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 TutorLearn face to face in Glasgow
Prefer in-person lessons? Visit the ExpertTutor Glasgow Southside centre.
See the centre