Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.
25 is the root. 4 and 36 are its children; 1 and 16 are children of 4; 9 is the left child of 16; 64 is the right child of 36 and 49 is the left child of 64. Use -1 for every empty pointer.
| Node | LeftPtr | RightPtr |
|---|---|---|
| 25 | arrow to 4 | arrow to 36 |
| 4 | arrow to 1 | arrow to 16 |
| 36 | -1 | arrow to 64 |
| 1 | -1 | -1 |
| 16 | arrow to 9 | -1 |
| 64 | arrow to 49 | -1 |
| 9 | -1 | -1 |
| 49 | -1 | -1 |
Five additional nodes (16, 36, 64, 9, 49) with correct data [1]
Correct -1 null pointers in all nodes and no extra ones where an arrow goes to a node [1]
Correct arrows from the correct left or right pointer box to each child [1]
All nodes in the correct places with nothing extra in the pointer boxes [1]
Use the index of each child as the pointer. FreePtr points to the first unused row, index 8.
| Index | LeftPtr | Data | RightPtr |
|---|---|---|---|
| 0 | 1 | 25 | 2 |
| 1 | 3 | 4 | 4 |
| 2 | -1 | 36 | 5 |
| 3 | -1 | 1 | -1 |
| 4 | 6 | 16 | -1 |
| 5 | 7 | 64 | -1 |
| 6 | -1 | 9 | -1 |
| 7 | -1 | 49 | -1 |
| 8 |
Write 8 in FreePtr (row 8 stays blank).
All eight filled rows correct [3]
Six or seven correct rows score 2 of those marks; three to five correct rows score 1.
FreePtr = 8 with the last row blank [1]
Go right if the node's data is smaller than Item, go left if it is larger, otherwise return the index.
FUNCTION SearchList(Item : INTEGER) RETURNS INTEGER
NullPtr ← -1
NowPtr ← RootPtr
WHILE NowPtr <> NullPtr
IF LinkList[NowPtr].Data < Item THEN
NowPtr ← LinkList[NowPtr].RightPtr
ELSE
IF LinkList[NowPtr].Data > Item THEN
NowPtr ← LinkList[NowPtr].LeftPtr
ELSE
RETURN NowPtr
ENDIF
ENDIF
ENDWHILE
RETURN NullPtr
ENDFUNCTIONRETURNS INTEGER [1]
NowPtr ← RootPtr [1]
LinkList[NowPtr].Data > Item [1]
NowPtr ← LinkList[NowPtr].LeftPtr [1]
▶ Whole paper
Video solution of the whole paper · by Zafar Ali Khan (ZAK). 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.