Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.
Follow the flowchart one box at a time. If List[B] is not greater than List[B + 1], swap them using T and set A to TRUE. At B = 5, go back to the start if A is TRUE. Only values that change are written in the table.
| A | B | List[1] | List[2] | List[3] | List[4] | List[5] | T |
|---|---|---|---|---|---|---|---|
| 15 | 17 | 20 | 5 | 9 | |||
| FALSE | 1 | 17 | 15 | 15 | |||
| TRUE | 2 | 20 | 15 | 15 | |||
| TRUE | 3 | ||||||
| TRUE | 4 | 9 | 5 | 5 | |||
| 5 | |||||||
| FALSE | 1 | 20 | 17 | 17 | |||
| TRUE | 2 | ||||||
| 3 | |||||||
| 4 | |||||||
| 5 | |||||||
| FALSE | 1 | ||||||
| 2 | |||||||
| 3 | |||||||
| 4 | |||||||
| 5 |
Column A correct [1]
Column B correct [1]
Column T correct [1]
Columns List[1] to List[5] with one error only [1]
Columns List[1] to List[5] all correct [1]
The algorithm is a bubble sort of the data in the array. [1]
It puts the data into descending order (largest first). [1]
▶ Topic lesson
A lesson on this topic · by Mr Bulmer's Learning Zone. 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.