Worked solution from the System Software Paper 3 Advanced Theory booklet, Part 2 of 2.
Work from the left. Each operator uses the two values before it.
5 2 – becomes (5 – 2); 5 4 + becomes (5 + 4). [1]
Then * joins them, then / 9: write (5 – 2) * (5 + 4) / 9 [1]
Push each number. At an operator, pop two values, calculate, push the result.
| Item read | Stack (bottom → top) |
|---|---|
| 5 | 5 |
| 2 | 5, 2 |
| – | 3 |
| 5 | 3, 5 |
| 4 | 3, 5, 4 |
| + | 3, 9 |
| * | 27 |
| 9 | 27, 9 |
| / | 3 |
5 and 2 pushed, then 3 after the subtraction [1]
5 and 4 pushed, then 9 after the addition [1]
27 after the multiplication [1]
9 pushed, then final answer 3 after the division [1]
Marks are given for correct stack stages like these.
Read the expression from left to right. [1]
Push each value onto the stack until an operator is reached. [1]
At an operator, pop the last two values, apply the operator, and push the result back. Repeat until the whole expression is read and one value is left. [1]
▶ Topic lesson
A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.