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

Q78 · 9618/23/O/N/23 Q3

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

Q789618/23/O/N/23original Q3Structured · 9 marks
Question 3 from 9618/23/O/N/23

Worked solution

(a)

Put the five items in order in consecutive places, with the front at D3 and the end at D5. One correct layout starts at index 2.

IndexArray
1
2D3
3D4
4D1
5D2
6D5
7
8

D3, D4, D1, D2 and D5 in order (or reversed) in five consecutive places [1]

VariableValue
FrontOfQueue2
EndOfQueue6
NumItems5

FrontOfQueue holds the index of D3 [1]

EndOfQueue holds the index of D5 [1]

(b)

Complete each step. The array has 8 elements, so the pointer wraps from 8 back to 1.

1. If NumItems is 8 (the queue is full) then jump to step 6. [1]

2. Increment EndOfQueue. [1]

3. If EndOfQueue = 9 then set EndOfQueue to 1. [1]

4. Increment NumItems. [1]

5. Set the element at the index stored in EndOfQueue to the value being added. [2]

KEY IDEAA circular queue wraps its pointer back to 1 after the last element and uses a count to know when it is full.
TOTAL 9 marks

Official mark scheme

Mark scheme for 9618/23/O/N/23 question 3
VIDEO
▶ Starts at Q3 (44:06)

Starts at Q3 (44:06) · by Zafar Ali Khan (ZAK). 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.