Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q34 · 9618/23/O/N/23 Q5

Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.

Q349618/23/O/N/23original Q5Structured · 6 marks
Question 5 from 9618/23/O/N/23

Worked solution

Dry run Process(2). Mix starts as 4, 2, 3, 5. The loop runs while Total < 20.

IndexValueTotalMix[1]Mix[2]Mix[3]Mix[4]
204235
3224535
4354585
25104589
251541389
2132842189
21328562189

Initialisation row [1]

Loop 1 correct (Total 2) [1]

Loop 2 correct (Total 5) [1]

Loop 3 correct (Total 10) [1]

Loop 4 correct (Total 15) [1]

Loop 5 correct (Total 28), then the final line Mix[1] ← 28 * 2 = 56 [1]

Notes: when Index is 4 the ELSE branch adds Mix[1] to Mix[4]. The new Index is (Value MOD 4) + 1, for example (13 MOD 4) + 1 = 2.

KEY IDEAIn a trace, apply MOD and the IF branch carefully each time and update only what each line changes.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/23/O/N/23 question 5
VIDEO
▶ Starts at Q5 (1:13:13)

Starts at Q5 (1:13:13) · 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.