Cambridge O Level Computer Science 2210 · 7.9 Writing and amending algorithms

Q116 · 2210/23/O/N/25 Q6

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8.

Q1162210/23/O/N/25original Q6Structured · 9 marks
Question 6 from 2210/23/O/N/25

Worked solution

(a)

Follow the flowchart. It searches ClassList and gives the position, or -1 if the name is not found.

NameOUTPUT
Ridwan5
Yan-1
Ella3

Any two rows correct [1]

All three rows correct [1]

(b)

Write: linear search [1]

(c)

Set Position and Count, input the name once, then loop through the array until the end or until the name is found.

Position ← -1
Count ← 1
OUTPUT "Please enter a name "
INPUT Name
REPEAT
    IF Name = ClassList[Count]
      THEN
        Position ← Count
        Count ← 6
      ELSE
        Count ← Count + 1
    ENDIF
UNTIL Count > 5
OUTPUT Position

Position and Count set before the loop [1]

Name input before (outside) the loop [1]

A suitable loop with a correct condition [1]

Name compared with ClassList[Count] [1]

Count increased by 1 each time [1]

Position output (the position found, or -1) [1]

A WHILE loop, or a FOR loop from 1 to 5, is also accepted.

KEY IDEAA linear search checks each item in order and keeps the position of the match, or -1 when there is none.
TOTAL 9 marks

Official mark scheme

Mark scheme for 2210/23/O/N/25 question 6
VIDEO
▶ Topic lesson

A lesson on this topic · by Mr Bulmer's Learning Zone. 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.