Cambridge O Level Computer Science 2210 · 7.7 Trace tables

Q47 · 2210/22/O/N/20 Q5

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.

Q472210/22/O/N/20original Q5Structured · 7 marks
Question 5 from 2210/22/O/N/20

Worked solution

(a)

Run the algorithm line by line. It swaps neighbours when the left one is smaller. In the first pass 45 and 56 swap, then 12 and 15 swap, so Flag is 1 and it repeats. The second pass makes no swaps, so Flag stays 0 and it stops.

FlagCountNum[0]Num[1]Num[2]Num[3]Num[4]Store
4556301215
0045
56
145
1
2
312
15
12
00
1
2
3

Flag column correct [1]

Count column correct [1]

Num[0] and Num[1] columns correct [1]

Num[2], Num[3] and Num[4] columns correct [1]

Store column correct [1]

(b)

The algorithm sorts (orders) the numbers [1]

into descending order, from largest to smallest. [1]

KEY IDEAThis is a bubble sort: keep swapping neighbours until a full pass makes no swaps.
TOTAL 7 marks

Official mark scheme

Mark scheme for 2210/22/O/N/20 question 5
VIDEO
▶ Whole paper

Video solution of the whole paper · by Quixotic Academy. 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.