9618/32/O/N/22 question 11: worked solution (October/November 2022, paper 32)

Show as plain text

Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2. Q6 9618/32/O/N/22 original Q11 Structured · 10 marks Worked solution (a) 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] (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 IDEA A 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 VIDEO ▶ Whole paper Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.