2210/22/O/N/20 question 5: worked solution (October/November 2020, paper 22)
Show as plain textHide 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. Q47 2210/22/O/N/20 original Q5 Structured · 7 marks 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. Flag Count Num [0] Num [1] Num [2] Num [3] Num [4] Store 45 56 30 12 15 0 0 45 56 1 45 1 2 3 12 15 12 0 0 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 IDEA This is a bubble sort: keep swapping neighbours until a full pass makes no swaps. TOTAL 7 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Quixotic Academy. Tap the picture to open it on YouTube.