Cambridge A2 Level Computer Science 9618 · 16.2 Translation Software

Q40 · 9618/33/O/N/25 Q7

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

Q409618/33/O/N/25original Q7Structured · 9 marks
Question 7 from 9618/33/O/N/25

Worked solution

(a)

Optimisation removes redundant code, simplifies expressions or reorders the code. [1]

The aim is to minimise storage size, memory use, power use or execution time (CPU time). [1]

(b)

Work in brackets first: (6 + 12) becomes 6 12 +. [1]

(16 – 10) becomes 16 10 –, then divide the two results: 16 10 – /. [1]

Multiply by 18: put 18 and * at the end. [1]

Write: 6 12 + 16 10 – / 18 *

(c)

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

StepItem readStack (bottom → top)
1c24
2a24, 4
3-20
4b20, 12
5d20, 12, 6
6+20, 18
7*360
8b360, 12
9c360, 12, 24
10+360, 36
11/10

c, a pushed, then - gives 20: stack 24 → 24, 4 → 20 [1]

b, d pushed, then + gives 18: stack 20, 12 → 20, 12, 6 → 20, 18 [1]

* gives the interim total 360, then b and c pushed and + gives 36: stack 360 → 360, 12 → 360, 12, 24 → 360, 36 [1]

/ gives the final total 10 [1]

KEY IDEABrackets are worked out first when converting to RPN, and an RPN operator always uses the top two stack items.
TOTAL 9 marks

Official mark scheme

Mark scheme for 9618/33/O/N/25 question 7
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.