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

Q76 · 9618/21/O/N/23 Q3

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

Q769618/21/O/N/23original Q3Structured · 8 marks
Question 3 from 9618/21/O/N/23

Worked solution

(a)

The array is filled from element 1 upwards, so the bottom item D2 goes in element 1.

Array elementData
8
7
6
5D1
4D3
3D4
2D5
1D2
VariableValue
TopOfStack5
BottomOfStack1

All values in the order and places shown [1]

TopOfStack = 5 (the element holding D1) [1]

BottomOfStack = 1 (the element holding D2) [1]

(b)

Complete the five steps:

1 If TopOfStack = 8 (the stack is full) then return FALSE [1]

2 Otherwise increment TopOfStack [1]

3 Use TopOfStack as an index to the array [1]

4 Set the element at this index (location or position) to the value (data or item) being added [1]

5 Return TRUE [1]

KEY IDEAA stack in an array uses a top index: check for full, move the index up, store the value, return TRUE.
TOTAL 8 marks

Official mark scheme

Mark scheme for 9618/21/O/N/23 question 3
VIDEO
▶ Starts at Q3 (15:42)

Starts at Q3 (15:42) · by Pseudocode Pro. 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.