9618/33/M/J/25 question 12: worked solution (May/June 2025, paper 33)
Show as plain textHide plain text
Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2. Q21 9618/33/M/J/25 original Q12 Structured · 7 marks Worked solution (a) Write two ADTs. Any two of these: stack , queue , linked list , binary tree , graph [1] (b) Take each item in turn. Keep it in Value. Shift larger items one place right, then drop Value into the gap. FOR Index ← 2 TO 1000 Value ← DataArray[Index] Position ← Index - 1 WHILE Position >= 1 AND DataArray[Position] > Value DataArray[Position + 1] ← DataArray[Position] Position ← Position - 1 ENDWHILE DataArray[Position + 1] ← Value NEXT Index Value ← DataArray[Index] before the inner loop [1] Inner loop (WHILE) that checks DataArray[Position] > Value [1] Moving the data to the next element and updating Position inside the loop [1] Value put back with DataArray[Position + 1] ← Value after the loop [1] Other correct insertion sorts also score, for example a FOR inner loop with an IF. (c) Write two ways the data affects speed. A sort is quicker if the data is already partially sorted , and likely slower if it is completely out of order [1] A sort takes longer when there are more items to sort, and less time when there are fewer [1] KEY IDEA Insertion sort keeps one value aside, shifts larger values along, then inserts it; sort speed depends on how ordered and how large the data is. TOTAL 7 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by rjmcompsci. Tap the picture to open it on YouTube.