Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms

Q19 · 9618/31/M/J/25 Q4

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

Q199618/31/M/J/25original Q4Structured · 7 marks
Question 4 from 9618/31/M/J/25

Worked solution

(a)

Insert each number by comparing with the nodes from the root. Go left if smaller, right if larger. 6: 6 < 36, 6 < 12, 6 > 3, so right of 3. 15: 15 < 36, 15 > 12, so right of 12. 41: 41 > 36, 41 > 40, so right of 40. 66: 66 > 36, 66 > 40, 66 > 41, so right of 41.

NodeLeft pointerRight pointer
36arrow to 12arrow to 40
12arrow to 3arrow to 15
40-1arrow to 41
3-1arrow to 6
6-1-1
15-1-1
41-1arrow to 66
66-1-1

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

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

Correct -1 null pointers added throughout [1]

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

(b)

Say what recursion is, then when it stops.

Recursion is a technique where a subroutine (function or procedure) calls itself to solve a problem [1]

It keeps calling itself until the base case (terminating condition) is reached, when no more recursive calls are made [1]

(c)

Write one ADT.

Stack [1]

KEY IDEAAdd a value to a binary tree by going left for smaller and right for larger until a null pointer is found.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/31/M/J/25 question 4
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.