Cambridge O Level Computer Science 2210 · 7.7 Trace tables

Q56 · 2210/22/M/J/23 Q9

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

Q562210/22/M/J/23original Q9Structured · 7 marks
Question 9 from 2210/22/M/J/23

Worked solution

(a)

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.

FCX[1]X[2]X[3]X[4]X[5]T
1015711
0110
1211010
351010
4710
5
01
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]

(b)

Write:

It is a (bubble) sort of the data in the array [1]

into ascending order [1]

KEY IDEAComparing neighbours, swapping them when out of order and repeating until no swap happens is a bubble sort.
TOTAL 7 marks

Official mark scheme

Mark scheme for 2210/22/M/J/23 question 9
VIDEO
▶ 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.