Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software

Q39 · 9618/32/O/N/25 Q8

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

Q399618/32/O/N/25original Q8Structured · 8 marks
Question 8 from 9618/32/O/N/25

Worked solution

(a)

Write: to improve the code so that it uses minimum resources, for example less memory, less storage or less CPU time. [1]

(b)

Rebuild the expression by reading the RPN left to right, using a stack.

a b - gives (a - b), then c + gives (a - b + c). [1]

c a - gives (c - a), and * multiplies the two results: (a - b + c) * (c - a). [1]

d / divides that by d. [1]

Write: (a - b + c) * (c - a) / d

(c)

Push each value. An operator takes the top two items, works out the answer and pushes it back. a = 3, b = 16, c = 9, d = 6.

StepItem readStack (bottom → top)
1c9
2a9, 3
3/3
4b3, 16
5d3, 16, 6
6-3, 10
7*30
8b30, 16
9+46

c, a pushed, then / gives 3: stack 9 → 9, 3 → 3 [1]

b, d pushed, then - gives 10: stack 3, 16 → 3, 16, 6 → 3, 10 [1]

* gives 30: stack 30 [1]

b pushed, then + gives the final answer: stack 30, 16 → 46 [1]

KEY IDEAIn RPN an operator uses the top two items on the stack and pushes its answer back.
TOTAL 8 marks

Official mark scheme

Mark scheme for 9618/32/O/N/25 question 8
VIDEO
▶ Starts at Q8 (1:06:00)

Starts at Q8 (1:06:00) · by Zafar Ali Khan (ZAK). 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.