Cambridge AS Level Computer Science 9618 · 12.3 Program Testing and Maintenance

Q53 · 9618/21/M/J/25 Q6

Worked solution from the Software Development Paper 2 Problem-solving and Programming booklet, Part 3 of 3.

Q539618/21/M/J/25original Q6Structured · 12 marks
Question 6 from 9618/21/M/J/25

Worked solution

(a)

Test the edges of 0 to 60, a value outside it and one more normal value:

Type of test dataTest data valueExpected outcome
normal36data item is accepted
boundary0data item is accepted
boundary60data item is accepted
abnormal61data item is rejected
normal15data 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 IDEAAn efficient bubble sort stops when no swap happens and does not re-check the sorted end.
TOTAL 12 marks

Official mark scheme

Mark scheme for 9618/21/M/J/25 question 6
VIDEO
▶ Whole paper

Video solution of the whole paper · by Sir Sikandar Raza. 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.