Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms

Q1 · 9618/31/M/J/21 Q8

Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.

Q19618/31/M/J/21original Q8Structured · 8 marks
Question 8 from 9618/31/M/J/21

Worked solution

(a)

Think about what changes how fast a sort runs. Write any two of these three:

The initial order of the data (already sorted, reversed or random) [1]

The number of data items to be sorted [1]

Other points that also score: the efficiency of the sorting algorithm chosen.

(b)

An insertion sort takes each item in turn and slides it back into the already sorted part. The score and both name parts must always move together.

YearSize ← 249
FOR Student ← 2 TO YearSize
    Temp1 ← Score[Student]
    Temp2 ← Name[Student,1]
    Temp3 ← Name[Student,2]
    Counter ← Student
    WHILE Counter > 1 AND Score[Counter - 1] < Temp1
        Score[Counter] ← Score[Counter - 1]
        Name[Counter,1] ← Name[Counter - 1,1]
        Name[Counter,2] ← Name[Counter - 1,2]
        Counter ← Counter - 1
    ENDWHILE
    Score[Counter] ← Temp1
    Name[Counter,1] ← Temp2
    Name[Counter,2] ← Temp3
NEXT Student

Any six of these seven points earn the 6 marks:

A FOR loop that goes through the whole year group [1]

The score being inserted is stored in a temporary variable [1]

The two name parts are stored in temporary variables too [1]

A WHILE loop with a correct exit condition (reaches the start, or the score before is not smaller) [1]

All three data items (score and both name parts) are moved along one place [1]

The counter is updated correctly inside the WHILE loop [1]

Other points that also score: the score and both name parts are put into the gap at the end.

KEY IDEAAn insertion sort stores the item, shifts larger items along until the gap is right, then drops the item in, moving every linked array together.
TOTAL 8 marks

Official mark scheme

Mark scheme for 9618/31/M/J/21 question 8
VIDEO
▶ Topic lesson

A lesson on this topic · by rjmcompsci. 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.