9618/21/O/N/25 question 5: worked solution (October/November 2025, paper 21)

Show as plain text

Cambridge AS Level Computer Science 9618 · 11.2 Constructs Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3. Q63 9618/21/O/N/25 original Q5 Structured · 6 marks Worked solution (a)(i) Write that -1 is not a valid array index (the array runs from 1 to 10000), so it shows that nothing has been found. [1] (a)(ii) Write that the outer clause tests whether the current element matches the search string. [1] (a)(iii) Write that FoundAt is only changed to the current index if it still holds -1 . Once a match is stored, FoundAt is no longer -1, so later matches do not change it. [1] (b)(i) Write that the FOR loop keeps going and keeps comparing after the first match is found , which wastes time. [1] (b)(ii) Construct: a conditional loop , such as WHILE or REPEAT UNTIL. [1] Justification: the search can stop as soon as the first match is found . [1] KEY IDEA When you only need the first match, use a conditional loop that stops as soon as it is found. TOTAL 6 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by CSFeedbySirNisarAli. Tap the picture to open it on YouTube.