Cambridge AS Level Computer Science 9618 · 10.4 Introduction to Abstract Data Types (ADT)

Q69 · 9618/21/O/N/21 Q3

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.

Q699618/21/O/N/21original Q3Structured · 13 marks
Question 3 from 9618/21/O/N/21

Worked solution

(a)(i)

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]

(a)(ii)

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]

(a)(iii)

Write: there is only one item in the queue [1]

(b)(i)

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.

IndexDataPointer
0Frog
1Cat
2FishFront of queue
3Elk
4Wasp
5Bee
6MouseEnd 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.

(b)(ii)

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.

IndexDataPointer
0SharkEnd of queue
1(Cat)
2(Fish)
3(Elk)
4WaspFront of queue
5Bee
6Mouse
7Dolphin

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]

(c)

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]

KEY IDEAIn a circular queue both pointers move forward and wrap round to the start; check for full before adding.
TOTAL 13 marks

Official mark scheme

Mark scheme for 9618/21/O/N/21 question 3
VIDEO
▶ 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.