Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.
Follow the alphabet: Daisy → Foxglove → Iris → Lily → Lupin → Rose. Only the six names left in the list are shown.
| Index | Flower | NextPointer |
|---|---|---|
| 1 | Rose | 0 |
| 3 | Foxglove | 4 |
| 4 | Iris | 9 |
| 5 | Daisy | 3 |
| 8 | Lupin | 1 |
| 9 | Lily | 8 |
HeadPointer = 5 (Daisy is now first) [1]
Any three NextPointer values correct [1]
All six NextPointer values correct [1]
Loop until the pointer is 0. If the name matches, remember it and set Pointer to 0 to stop. Otherwise follow NextPointer.
Pointer ← HeadPointer
Found ← 0
OUTPUT "Enter a flower name "
INPUT FlowerName
WHILE Pointer <> 0
IF Flower[Pointer] = FlowerName THEN
Found ← Pointer
Pointer ← 0
ELSE
Pointer ← NextPointer[Pointer]
ENDIF
ENDWHILE
IF Found <> 0 THEN
OUTPUT Flower[Found], " is found"
ELSE
OUTPUT "The flower is not in the list"
ENDIFINPUT FlowerName [1]
WHILE Pointer <> 0 [1]
Pointer ← NextPointer[Pointer] [1]
IF Found <> 0 THEN (the official answer also accepts IF Pointer = 0 THEN on this line) [1]
OUTPUT a suitable not-found message [1]
Write any two of these:
Add a free list pointer [1]
...so that the unused (deleted) space can be reused [1]
Other points that also score: ...held as a linked list of free space.
▶ Whole paper
Video solution of the whole paper · by qiphyedu. 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.