Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.
Follow the flowchart. If X[C] < X[C + 1] nothing is swapped. Otherwise the two values swap (using T) and F becomes 1. C goes up by 1 each time. After C reaches 5, the algorithm repeats if F = 1. Each row shows the values after the step, so T = 10 is first set at C = 1 and stays at 10 for the swaps that follow.
| F | C | X[1] | X[2] | X[3] | X[4] | X[5] | T |
|---|---|---|---|---|---|---|---|
| 10 | 1 | 5 | 7 | 11 | |||
| 0 | 1 | 10 | |||||
| 1 | 2 | 1 | 10 | 10 | |||
| 3 | 5 | 10 | 10 | ||||
| 4 | 7 | 10 | |||||
| 5 | |||||||
| 0 | 1 | ||||||
| 2 | |||||||
| 3 | |||||||
| 4 | |||||||
| 5 |
On the second pass nothing swaps, F stays 0 and the algorithm stops. The array ends as 1, 5, 7, 10, 11.
F column correct [1]
C column correct [1]
T column correct [1]
X[1] to X[5] columns all correct (one mark if only one error) [2]
Write:
It is a (bubble) sort of the data in the array [1]
into ascending order [1]
▶ Whole paper
Video solution of the whole paper · by CS BY AQIB KHAN. 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.