Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.
Name a different ADT, then give two features.
Example: Queue [1]
Any two features: data is added at the back and removed from the front (FIFO); a pointer to the front and a pointer to the back; each element holds one data item; it may be circular [2]
Another accepted answer is a linked list: each node holds data and a pointer to the next node, a start pointer, and the last node has a null pointer.
Any five of these:
Declare a 1D array of data type STRING [1]
The number of elements is the size of the stack [1]
Declare an integer stack pointer used as the index of the array [1]
Store each stack item in one array element; the pointer is set to show an empty stack at the start [1]
Push adds an item at the pointer and Pop removes it, and each routine checks for full or empty first [1]
Other accepted points: an integer for the maximum size of the stack.
PUSH moves the pointer up, POP moves it down. Group 2 pops E, D and X, so SP ends at 952. In Group 3, A goes to 953, B to 954, B is popped and C goes to 954. Popped values stay in their cells.
| Location | After Group 1 | After Group 2 | After Group 3 |
|---|---|---|---|
| 957 | |||
| 956 | |||
| 955 | E ←SP | E | E |
| 954 | D | D | C ←SP |
| 953 | X | X | A |
| 952 | Y | Y ←SP | Y |
| 951 | Z | Z | Z |
| 950 | P | P | P |
Data after Group 1 correct, blank cells empty [1]
Data after Group 2 correct [1]
Data after Group 3 correct [1]
SP after Group 1 points to location 955 [1]
SP after Group 2 points to 952 and SP after Group 3 points to 954 [1]
▶ Whole paper
Video solution of the whole paper · by Audere Prep. 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.