9618/21/M/J/25 question 6: worked solution (May/June 2025, paper 21)

Show as plain text

Cambridge AS Level Computer Science 9618 · 12.3 Program Testing and Maintenance Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3. Q53 9618/21/M/J/25 original Q6 Structured · 12 marks Worked solution (a) Test the edges of 0 to 60, a value outside it and one more normal value: Type of test data Test data value Expected outcome normal 36 data item is accepted boundary 0 data item is accepted boundary 60 data item is accepted abnormal 61 data item is rejected normal 15 data item is accepted Row with 0 (accepted) [1] Row with 60 (accepted) [1] Row with 61 or more (abnormal, rejected) [1] Row with another normal value, such as 15 (accepted) [1] (b) Use a bubble sort with a flag, and shrink the range after each pass. Swap both columns so the sensor ID stays with its value: PROCEDURE Sort() DECLARE Temp, J, Boundary : INTEGER DECLARE NoSwaps : BOOLEAN Boundary ← 1999 REPEAT NoSwaps ← TRUE FOR J ← 1 TO Boundary IF Reading[J, 1] > Reading[J + 1, 1] THEN Temp ← Reading[J, 1] Reading[J, 1] ← Reading[J + 1, 1] Reading[J + 1, 1] ← Temp Temp ← Reading[J, 2] Reading[J, 2] ← Reading[J + 1, 2] Reading[J + 1, 2] ← Temp NoSwaps ← FALSE ENDIF NEXT J Boundary ← Boundary - 1 UNTIL NoSwaps = TRUE ENDPROCEDURE Procedure heading and ending [1] Conditional outer loop (REPEAT ... UNTIL) with a Boolean flag declared and set before each pass [1] Inner FOR loop with the range 1 to 1999 (Boundary) [1] Compare element J with element J+1 in column 1 [1] Temp declared and the sensor values swapped [1] The sensor ID values (column 2) swapped as well [1] Flag set to show a swap, and the loop ends when no swap occurs [1] Boundary reduced after each pass [1] Other correct bubble sorts also score, for example a WHILE loop. KEY IDEA An efficient bubble sort stops when no swap happens and does not re-check the sorted end. TOTAL 12 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Sir Sikandar Raza. Tap the picture to open it on YouTube.