Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.
Dry run Process(2). Mix starts as 4, 2, 3, 5. The loop runs while Total < 20.
| Index | Value | Total | Mix[1] | Mix[2] | Mix[3] | Mix[4] |
|---|---|---|---|---|---|---|
| 2 | 0 | 4 | 2 | 3 | 5 | |
| 3 | 2 | 2 | 4 | 5 | 3 | 5 |
| 4 | 3 | 5 | 4 | 5 | 8 | 5 |
| 2 | 5 | 10 | 4 | 5 | 8 | 9 |
| 2 | 5 | 15 | 4 | 13 | 8 | 9 |
| 2 | 13 | 28 | 4 | 21 | 8 | 9 |
| 2 | 13 | 28 | 56 | 21 | 8 | 9 |
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.
▶ 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.