9618/21/O/N/21 question 3: worked solution (October/November 2021, paper 21)
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. Q69 9618/21/O/N/21 original Q3 Structured · 13 marks 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. Index Data Pointer 0 Frog 1 Cat 2 Fish Front of queue 3 Elk 4 Wasp 5 Bee 6 Mouse End 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. Index Data Pointer 0 Shark End of queue 1 (Cat) 2 (Fish) 3 (Elk) 4 Wasp Front of queue 5 Bee 6 Mouse 7 Dolphin 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 IDEA In a circular queue both pointers move forward and wrap round to the start; check for full before adding. TOTAL 13 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Mr Saem. Tap the picture to open it on YouTube.