Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q32 · 9618/22/O/N/23 Q5

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

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

Worked solution

Dry run Process(3) one line at a time. Mix starts as 1, 3, 4, 2. Each row below shows the values after one pass of the loop.

IndexValueCountMix[1]Mix[2]Mix[3]Mix[4]
301342
4411332
2221331
3331231
3341221
2251211
22512110

Initialisation row (Index 3, Count 0, Mix 1, 3, 4, 2) [1]

Loop 1 and loop 2 rows correct [2]

Loop 3 and loop 4 rows correct [2]

Loop 5 row correct, then the last row where Mix[4] ← 5 * 2 = 10 [1]

Marks are earned for each correct row, so check each Mix change: loop 1 changes Mix[3] to 3, loop 2 changes Mix[4] to 1, loop 3 changes Mix[2] to 2, loop 4 changes Mix[3] to 2, loop 5 changes Mix[3] to 1.

KEY IDEAWork through a trace table line by line and update only the variable that each line changes.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/22/O/N/23 question 5
VIDEO
▶ Starts at Q5 (26:45)

Starts at Q5 (26:45) · by Pseudocode Pro. 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.