9618/23/O/N/23 question 3: worked solution (October/November 2023, paper 23)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 10.4 Introduction to Abstract Data Types (ADT) Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4. Q78 9618/23/O/N/23 original Q3 Structured · 9 marks 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. Index Array 1 2 D3 3 D4 4 D1 5 D2 6 D5 7 8 D3, D4, D1, D2 and D5 in order (or reversed) in five consecutive places [1] Variable Value FrontOfQueue 2 EndOfQueue 6 NumItems 5 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 IDEA A 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 VIDEO ▶ Starts at Q3 (44:06) Starts at Q3 (44:06) · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.