9618/22/O/N/22 question 3: worked solution (October/November 2022, paper 22)

Show as 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. Q72 9618/22/O/N/22 original Q3 Structured · 13 marks Worked solution (a) Name a different ADT, then give two features. Example: Queue [1] Any two features: data is added at the back and removed from the front ( FIFO ); a pointer to the front and a pointer to the back ; each element holds one data item; it may be circular [2] Another accepted answer is a linked list : each node holds data and a pointer to the next node, a start pointer, and the last node has a null pointer. (b) Any five of these: Declare a 1D array of data type STRING [1] The number of elements is the size of the stack [1] Declare an integer stack pointer used as the index of the array [1] Store each stack item in one array element ; the pointer is set to show an empty stack at the start [1] Push adds an item at the pointer and Pop removes it, and each routine checks for full or empty first [1] Other accepted points: an integer for the maximum size of the stack. (c) PUSH moves the pointer up, POP moves it down. Group 2 pops E, D and X, so SP ends at 952. In Group 3, A goes to 953, B to 954, B is popped and C goes to 954. Popped values stay in their cells. Location After Group 1 After Group 2 After Group 3 957 956 955 E ←SP E E 954 D D C ←SP 953 X X A 952 Y Y ←SP Y 951 Z Z Z 950 P P P Data after Group 1 correct, blank cells empty [1] Data after Group 2 correct [1] Data after Group 3 correct [1] SP after Group 1 points to location 955 [1] SP after Group 2 points to 952 and SP after Group 3 points to 954 [1] KEY IDEA A stack works last in, first out: push raises the stack pointer, pop lowers it. TOTAL 13 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Audere Prep. Tap the picture to open it on YouTube.