Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software

Q24 · 9618/31/O/N/23 Q9

Worked solution from the System Software Paper 3 Advanced Theory booklet, Part 2 of 2.

Q249618/31/O/N/23original Q9Structured · 9 marks
Question 9 from 9618/31/O/N/23

Worked solution

(a)(i)

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]

(a)(ii)

Push each number. At an operator, pop two values, calculate, push the result.

Item readStack (bottom → top)
55
25, 2
–3
53, 5
43, 5, 4
+3, 9
*27
927, 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.

(b)

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]

KEY IDEAEvaluate RPN with a stack: push values, and at each operator pop two, calculate and push the result.
TOTAL 9 marks

Official mark scheme

Mark scheme for 9618/31/O/N/23 question 9
VIDEO
▶ 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.