9618/32/M/J/23 question 11: worked solution (May/June 2023, paper 32)

Show as plain text

Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2. Q8 9618/32/M/J/23 original Q11 Structured · 10 marks Worked solution (a)(i) Match each description to its name in the code: Identifier Data type Description Queue STRING An array to store the contents of the queue. RearPointer INTEGER Points to the last item of the queue. Length INTEGER Indicates the number of items in the queue. FrontPointer INTEGER Points 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 IDEA A 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 VIDEO ▶ Whole paper Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.