Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms

Q20 · 9618/32/M/J/25 Q11

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

Q209618/32/M/J/25original Q11Structured · 6 marks
Question 11 from 9618/32/M/J/25

Worked solution

(a)

Compare each string with the nodes from the root, in alphabetical order. Go left if earlier, right if later. 0 means a null pointer. Aa: before Pp and before Gg, so left of Gg. Mm: before Pp, after Gg, after Kk, so right of Kk. Ss: after Pp, after Rr, so right of Rr. Xx: after Pp, Rr and Ss, so right of Ss.

NodeLeft pointerRight pointer
Pparrow to Ggarrow to Rr
Ggarrow to Aaarrow to Kk
Rr0arrow to Ss
Kk0arrow to Mm
Aa00
Mm00
Ss0arrow to Xx
Xx00

Any two new nodes added correctly with correct data [1]

The other two nodes added correctly, with all arrows starting from the correct pointer boxes [1]

Correct null pointers (0) added throughout [1]

No entries in the other pointer boxes and all nodes correctly placed and connected [1]

(b)

Give the feature, then an example.

Feature: recursion is beneficial when a problem naturally breaks down into smaller versions of itself [1]

Example: calculating a factorial (or a mathematical series, Fibonacci numbers, compound interest, tree traversal, or evaluating RPN expressions) [1]

KEY IDEARecursion suits problems that split into smaller copies of the same problem; a tree places strings by alphabetical order.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/32/M/J/25 question 11
VIDEO
▶ Topic lesson

A lesson on this topic · by rjmcompsci. 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.