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

Q84 · 9618/23/M/J/25 Q2

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

Q849618/23/M/J/25original Q2Structured · 11 marks
Question 2 from 9618/23/M/J/25

Worked solution

(a)(i)

The oldest value is at the bottom of the stack, and TopOfStack is at 403. 409 - 403 = 6 more pushes.

Memory location of the value on the stack longest: 400 [1]

Number of pushes to make TopOfStack 409: 6 [1]

(a)(ii)

Work through the operations. Push T (408), pop T, pop A (top is now 406 C), push Z (407), push X (408), pop X, push Y (408).

Memory locationValue
409
408'Y' ← TopOfStack
407'Z'
406'C'
405'F'
404'K'
403'B'
402'S'
401'R'
400'D'

TopOfStack points to 408 and 'Y' is in 408 [1]

'C' in 406 and 'Z' in 407 [1]

'F', 'K', 'B', 'S', 'R', 'D' unchanged in 405 to 400, and 409 empty [1]

(b)(i)

Put the names in alphabetical order: Earth, Jupiter, Mercury, Neptune, Saturn, Uranus. Each pointer holds the index of the next name.

IndexDataPointer
0"Neptune"2
1"Jupiter"4
2"Saturn"5
3"Earth"1
4"Mercury"0
5"Uranus"-1

Earth has pointer 1 [1]

Uranus has pointer -1 [1]

The other four pointers are correct (Jupiter 4, Mercury 0, Neptune 2, Saturn 5) [1]

(b)(ii)

Earth is first alphabetically and is at index 3, so StartPointer = 3 [1]

(c)

Any two of these:

The first value added is the first value removed (FIFO) [1]

Two pointers are needed, one for the start (front) and one for the end (rear) [1]

It may work as a circular queue

It is used with enqueue and dequeue operations

KEY IDEAKnow how a stack (last in, first out) and a linked list (pointers give the order) change, and that a queue is first in, first out.
TOTAL 11 marks

Official mark scheme

Mark scheme for 9618/23/M/J/25 question 2
VIDEO
▶ Whole paper

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