2210/22/M/J/23 question 9: worked solution (May/June 2023, paper 22)

Show as plain text

Cambridge O Level Computer Science 2210 · 7.7 Trace tables Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8. Q56 2210/22/M/J/23 original Q9 Structured · 7 marks 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. F C X [1] X [2] X [3] X [4] X [5] T 10 1 5 7 11 0 1 10 1 2 1 10 10 3 5 10 10 4 7 10 5 0 1 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 IDEA Comparing neighbours, swapping them when out of order and repeating until no swap happens is a bubble sort. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by CS BY AQIB KHAN. Tap the picture to open it on YouTube.