Cambridge AS Level Computer Science 9618 · 10.4 Introduction to Abstract Data Types (ADT)

Q67 · 9618/21/M/J/21 Q6

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4.

Q679618/21/M/J/21original Q6Structured · 6 marks
Question 6 from 9618/21/M/J/21

Worked solution

(a)

Explain the steps in order (any four of these six points score):

Check that there is a free node available in the free list [1]

Search the list for the correct place: B goes after A and before C [1]

Store the data value B in the first node of the free list [1]

Change the pointer of A so it points to the node containing B (instead of C) [1]

Other points that also score: set the pointer of B to point to the node containing C; move the start pointer of the free list on to the next free node.

(b)

Write either of these:

Use one 1D array to store the data and a second 1D array to store the pointers [1]

Use an integer variable for the start pointer and another integer variable for the next free pointer [1]

Alternative: define a record type with a data field and a pointer field and declare a 1D array of that type, plus the two integer variables.

KEY IDEAInserting into a linked list means taking a node from the free list, then changing two pointers; arrays and pointer variables can model it.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/21/M/J/21 question 6
VIDEO
▶ Whole paper

Video solution of the whole paper · by Papersdock. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.