Cambridge O Level Computer Science 2210 · 7.7 Trace tables

Q59 · 2210/21/M/J/24 Q6

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

Q592210/21/M/J/24original Q6Structured · 10 marks
Question 6 from 2210/21/M/J/24

Worked solution

(a)

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.

LimitCount[1][2][3][4][5][6][7]FlagSwapResultOUTPUT
7147
250
352
460
580
663
770
8TRUE
1FALSE
2
3
4
580
6380TRUE
680
7080TRUE
7
1FALSE
2
3
4
5
6
7
460

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]

(b)

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]

KEY IDEAA bubble sort repeats passes until a pass makes no swaps, and the middle value of the sorted list is the median.
TOTAL 10 marks

Official mark scheme

Mark scheme for 2210/21/M/J/24 question 6
VIDEO
▶ 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.