Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.
The oldest value is at the bottom of the stack, and TopOfStack is at 403. 409 - 403 = 6 more pushes.
Memory location of the value on the stack longest: 400 [1]
Number of pushes to make TopOfStack 409: 6 [1]
Work through the operations. Push T (408), pop T, pop A (top is now 406 C), push Z (407), push X (408), pop X, push Y (408).
| Memory location | Value |
|---|---|
| 409 | |
| 408 | 'Y' ← TopOfStack |
| 407 | 'Z' |
| 406 | 'C' |
| 405 | 'F' |
| 404 | 'K' |
| 403 | 'B' |
| 402 | 'S' |
| 401 | 'R' |
| 400 | 'D' |
TopOfStack points to 408 and 'Y' is in 408 [1]
'C' in 406 and 'Z' in 407 [1]
'F', 'K', 'B', 'S', 'R', 'D' unchanged in 405 to 400, and 409 empty [1]
Put the names in alphabetical order: Earth, Jupiter, Mercury, Neptune, Saturn, Uranus. Each pointer holds the index of the next name.
| Index | Data | Pointer |
|---|---|---|
| 0 | "Neptune" | 2 |
| 1 | "Jupiter" | 4 |
| 2 | "Saturn" | 5 |
| 3 | "Earth" | 1 |
| 4 | "Mercury" | 0 |
| 5 | "Uranus" | -1 |
Earth has pointer 1 [1]
Uranus has pointer -1 [1]
The other four pointers are correct (Jupiter 4, Mercury 0, Neptune 2, Saturn 5) [1]
Earth is first alphabetically and is at index 3, so StartPointer = 3 [1]
Any two of these:
The first value added is the first value removed (FIFO) [1]
Two pointers are needed, one for the start (front) and one for the end (rear) [1]
It may work as a circular queue
It is used with enqueue and dequeue operations
▶ 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.