Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.
Refine the two main steps into smaller steps, using structured English only (no pseudocode statements):
Use a variable as an index (position) to point at the elements of the array [1]
Repeat the whole pass over the array until it is sorted, with an outer loop that goes round once for each element [1]
Inside it, use an inner loop that goes through the array from the first element, and stops one place earlier each time because the largest values are already at the end [1]
Compare the element at the current position with the next element [1]
If the current element is greater than the next one, swap them [1]
Describe the swap: copy one value to a temporary place, put the other value in its position, then put the temporary value in the other position [1]
A more efficient algorithm that sorts the array correctly is also credited, but only 6 marks can be given.
Follow the flowchart box by box. The loop has two conditions, so use a WHILE loop:
Count ← 1
Flag ← FALSE
WHILE Flag = FALSE AND Count <= 5
CALL ReBoot()
Count ← Count + 1
Flag ← Check()
ENDWHILE
IF Flag = FALSE THEN
CALL Alert(27)
ENDIFCount and Flag both set before the loop [1]
A WHILE ... ENDWHILE loop (or REPEAT ... UNTIL) [1]
The loop condition includes both Flag = FALSE and Count <= 5 [1]
ReBoot() is called and Count is increased inside the loop [1]
The value returned by Check() is assigned to Flag inside the loop [1]
After the loop, Flag is tested and Alert(27) is called, outside the loop [1]
▶ Whole paper
Video solution of the whole paper · by Mr Saem. 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.