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

Q72 · 9618/22/O/N/22 Q3

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

Q729618/22/O/N/22original Q3Structured · 13 marks
Question 3 from 9618/22/O/N/22

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.

LocationAfter Group 1After Group 2After Group 3
957
956
955E ←SPEE
954DDC ←SP
953XXA
952YY ←SPY
951ZZZ
950PPP

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 IDEAA stack works last in, first out: push raises the stack pointer, pop lowers it.
TOTAL 13 marks

Official mark scheme

Mark scheme for 9618/22/O/N/22 question 3
VIDEO
▶ Whole paper

Video solution of the whole paper · by Audere Prep. 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.