Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.
Octopus goes after Elk, which is at position 3:
The end of queue pointer moves up by 1 to point at location 4 [1]
The value "Octopus" is stored in location 4 [1]
The front of queue pointer is at location 0 (Frog):
The value "Frog" (at the front of queue pointer, location 0) is assigned to AnimalName [1]
The front of queue pointer moves up by 1 to location 1 ("Cat") [1]
Write: there is only one item in the queue [1]
Add Wasp, Bee and Mouse in locations 4, 5 and 6. Removing two items moves the front pointer from 0 to 2. The end pointer stays at 6.
| Index | Data | Pointer |
|---|---|---|
| 0 | Frog | |
| 1 | Cat | |
| 2 | Fish | Front of queue |
| 3 | Elk | |
| 4 | Wasp | |
| 5 | Bee | |
| 6 | Mouse | End of queue |
| 7 |
Front of queue pointer at location 2 and end of queue pointer at location 6 [2]
Wasp, Bee and Mouse in locations 4, 5 and 6 [1]
Removed items may be left or crossed out in the array; only the pointers show what is removed.
The front pointer is at 3 and the end pointer at 6 (Ant in location 7 is an old value left over). Remove one item: the front pointer moves from 3 to 4. Add Dolphin in location 7 (it replaces Ant). Add Shark: the end pointer wraps round from 7 to 0.
| Index | Data | Pointer |
|---|---|---|
| 0 | Shark | End of queue |
| 1 | (Cat) | |
| 2 | (Fish) | |
| 3 | (Elk) | |
| 4 | Wasp | Front of queue |
| 5 | Bee | |
| 6 | Mouse | |
| 7 | Dolphin |
Both pointers correct: front at location 4, end at location 0 [1]
All data values as shown: Shark in 0, Wasp, Bee, Mouse in 4 to 6 and Dolphin in 7 (the old values in 1 to 3 may stay) [1]
Write the steps in order:
Work out the new end pointer value; if it is equal to the front of queue pointer, the queue is full, so report an error [1]
Otherwise increment the end of queue pointer [1]
Wrap round to the start of the array (location 0) when the pointer goes past the last location [1]
▶ Whole paper
Video solution of the whole paper · by Mr Saem. 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.