2210/21/M/J/24 question 6: worked solution (May/June 2024, paper 21)
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. Q59 2210/21/M/J/24 original Q6 Structured · 10 marks 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. Limit Count [1] [2] [3] [4] [5] [6] [7] Flag Swap Result OUTPUT 7 1 47 2 50 3 52 4 60 5 80 6 63 7 70 8 TRUE 1 FALSE 2 3 4 5 80 63 80 TRUE 6 80 70 80 TRUE 7 1 FALSE 2 3 4 5 6 7 4 60 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 IDEA A 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 VIDEO ▶ Whole paper Video solution of the whole paper · by ZAINEMATICS. Tap the picture to open it on YouTube.