Cambridge AS Level Computer Science 9618 · 11.2 Constructs

Q63 · 9618/21/O/N/25 Q5

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

Q639618/21/O/N/25original Q5Structured · 6 marks
Question 5 from 9618/21/O/N/25

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 IDEAWhen you only need the first match, use a conditional loop that stops as soon as it is found.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/21/O/N/25 question 5
VIDEO
▶ Whole paper

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