Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.
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.
| Index | Value | Count | Mix[1] | Mix[2] | Mix[3] | Mix[4] |
|---|---|---|---|---|---|---|
| 3 | 0 | 1 | 3 | 4 | 2 | |
| 4 | 4 | 1 | 1 | 3 | 3 | 2 |
| 2 | 2 | 2 | 1 | 3 | 3 | 1 |
| 3 | 3 | 3 | 1 | 2 | 3 | 1 |
| 3 | 3 | 4 | 1 | 2 | 2 | 1 |
| 2 | 2 | 5 | 1 | 2 | 1 | 1 |
| 2 | 2 | 5 | 1 | 2 | 1 | 10 |
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.
▶ 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.