Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms

Q8 · 9618/32/M/J/23 Q11

Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.

Q89618/32/M/J/23original Q11Structured · 10 marks
Question 11 from 9618/32/M/J/23

Worked solution

(a)(i)

Match each description to its name in the code:

IdentifierData typeDescription
QueueSTRINGAn array to store the contents of the queue.
RearPointerINTEGERPoints to the last item of the queue.
LengthINTEGERIndicates the number of items in the queue.
FrontPointerINTEGERPoints to the first item of the queue.

Queue and RearPointer correct [1]

Length and FrontPointer correct [1]

(a)(ii)

Both pointers start at -1 and the length at 0. Only add an item if the queue is not full, move the rear pointer (wrapping round to 0), store the item, then increase Length.

PROCEDURE Initialise
    FrontPointer ← -1
    RearPointer ← -1
    Length ← 0
ENDPROCEDURE

PROCEDURE Enqueue(NewItem : STRING)
    IF Length < MaxLength THEN
        RearPointer ← RearPointer + 1
        IF RearPointer > MaxLength - 1 THEN
            RearPointer ← 0
        ENDIF
        Queue[RearPointer] ← NewItem
        Length ← Length + 1
    ENDIF
ENDPROCEDURE

RearPointer ← -1 [1]

Length ← 0 [1]

IF Length < MaxLength THEN [1]

RearPointer ← RearPointer + 1 [1]

Queue[RearPointer] ← NewItem [1]

(b)

Write any three of these:

Print jobs should be done in the order they arrive [1]

A queue is first in, first out, so the first job sent is the first printed [1]

With a stack (last in, first out), the first job would wait until every other job had been printed [1]

KEY IDEAA circular queue wraps its pointers back to 0, and a queue suits print jobs because the oldest job goes first.
TOTAL 10 marks

Official mark scheme

Mark scheme for 9618/32/M/J/23 question 11
VIDEO
▶ Whole paper

Video solution of the whole paper · by qiphyedu. 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.