Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.
The first loop inputs 7 numbers into the array. The second part is a bubble sort: Flag is set to FALSE at the start of each pass and TRUE whenever a swap happens, and passes repeat until one has no swap. Finally Result = 7 DIV 2 + 1 = 4 and Numbers[4] is output.
| Limit | Count | [1] | [2] | [3] | [4] | [5] | [6] | [7] | Flag | Swap | Result | OUTPUT |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 7 | 1 | 47 | ||||||||||
| 2 | 50 | |||||||||||
| 3 | 52 | |||||||||||
| 4 | 60 | |||||||||||
| 5 | 80 | |||||||||||
| 6 | 63 | |||||||||||
| 7 | 70 | |||||||||||
| 8 | TRUE | |||||||||||
| 1 | FALSE | |||||||||||
| 2 | ||||||||||||
| 3 | ||||||||||||
| 4 | ||||||||||||
| 5 | 80 | |||||||||||
| 63 | 80 | TRUE | ||||||||||
| 6 | 80 | |||||||||||
| 70 | 80 | TRUE | ||||||||||
| 7 | ||||||||||||
| 1 | FALSE | |||||||||||
| 2 | ||||||||||||
| 3 | ||||||||||||
| 4 | ||||||||||||
| 5 | ||||||||||||
| 6 | ||||||||||||
| 7 | ||||||||||||
| 4 | 60 |
Limit column correct [1]
Count column correct [1]
Array columns correct for the input stage [1]
Array columns correct for the sort stage (80 moves to the end, 63 and 70 move up) [1]
Flag column correct [1]
Swap column correct [1]
Result and OUTPUT columns correct (Result 4, OUTPUT 60) [1]
Write:
A set of numbers is input and stored in an array [1]
The numbers are sorted into ascending order (a bubble sort) [1]
The middle (median) value is found and output [1]
▶ Whole paper
Video solution of the whole paper · by ZAINEMATICS. 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.