Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.
Work through the loop one pass at a time. Start with New = 8, Last = -1, Current = 2. Keep going while Data[Current] is less than 1043.
| Value | Start | Unused | New | Last | Current |
|---|---|---|---|---|---|
| 1043 | 2 | 8 | 8 | -1 | 2 |
| 2 | 3 | ||||
| 3 | 1 | ||||
| 1 | 7 | ||||
| 7 | 4 |
First row: 1043, 2, 8, 8, -1, 2 [1]
Last 2 and Current 3 (Data[2] = 1007 is less than 1043) [1]
Last 3 and Current 1 [1]
Last 1 and Current 7, then Last 7 and Current 4. The loop stops because Data[4] = 1056 is not less than 1043 [1]
Data[8] ← 1043. Pointer[8] ← Pointer[7] = 4. Pointer[7] ← 8. All other values stay the same.
| Index | Data | Pointer |
|---|---|---|
| 1 | 1018 | 7 |
| 2 | 1007 | 3 |
| 3 | 1010 | 1 |
| 4 | 1056 | 6 |
| 5 | 1092 | -1 |
| 6 | 1062 | 5 |
| 7 | 1034 | 8 |
| 8 | 1043 | 4 |
| 9 | 0 | 10 |
| 10 | 0 | -1 |
Data row 8 contains 1043 [1]
Pointer row 7 contains 8 and Pointer row 8 contains 4 [1]
All other rows in both arrays unchanged [1]
The ADT is a linked list. [1]
Place() inserts a new value (node) into the linked list, in order. [1]
▶ Whole paper
Video solution of the whole paper · by Awab Aqib. 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.