Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms

Q6 · 9618/32/O/N/22 Q11

Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.

Q69618/32/O/N/22original Q11Structured · 10 marks
Question 11 from 9618/32/O/N/22

Worked solution

(a)

Follow the alphabet: Daisy → Foxglove → Iris → Lily → Lupin → Rose. Only the six names left in the list are shown.

IndexFlowerNextPointer
1Rose0
3Foxglove4
4Iris9
5Daisy3
8Lupin1
9Lily8

HeadPointer = 5 (Daisy is now first) [1]

Any three NextPointer values correct [1]

All six NextPointer values correct [1]

(b)

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"
ENDIF

INPUT 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]

(c)

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.

KEY IDEAA linked list follows pointers from the head until 0, and a free-list pointer lets deleted space be reused.
TOTAL 10 marks

Official mark scheme

Mark scheme for 9618/32/O/N/22 question 11
VIDEO
▶ 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.