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

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. Q71 9618/21/O/N/22 original Q4 Structured · 12 marks Worked solution (a)(i) Draw new nodes for 'A' and 'K', leave out 'J' and 'L', and change only the pointers. The list in order is A, C, K. Draw a new node holding 'A' and a new node holding 'K' [1] Draw the Start pointer pointing to node 'A' [1] Draw the pointer from node 'A' to node 'C', and from node 'C' to node 'K' [1] Draw a null pointer (Ø) in node 'K'; the nodes 'J' and 'L' have no pointers to them [1] (a)(ii) Write two points: In a linked list the pointers decide the order , so only pointers need to change when data changes [1] It is easier to add and delete items and keep the right order; in an array other items must be moved along [1] (a)(iii) Write two points: Extra memory is needed to store the pointers as well as the data [1] A linked list is more complex to set up and program [1] (b) Any four of these: Declare two 1D arrays [1] One array holds the data and the other holds the pointers [1] Elements with the same index together make one node [1] A variable (INTEGER) for the start pointer , which gives the index of the first node [1] Other accepted points: a value for the null pointer (for example 0 or -1), a free list pointer to unused nodes, and routines to add, delete and search. Alternative: define a record type with a data field and a pointer field, then declare one array of that record type. KEY IDEA A linked list keeps order with pointers, so inserting or deleting only changes pointers, but it costs extra memory for the pointers. TOTAL 12 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Pseudocode Pro. Tap the picture to open it on YouTube.