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

Q70 · 9618/21/M/J/22 Q4

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

Q709618/21/M/J/22original Q4Structured · 6 marks
Question 4 from 9618/21/M/J/22

Worked solution

(a)

The bottom of the stack holds the oldest value. A POP moves TopOfStack down one location each time.

Answer
The value that has been on the stack for the longest time.'H'
The memory location pointed to by TopOfStack if three POP operations are performed.206

Longest on the stack: 'H' (it is at the bottom, location 207) [1]

Location after three POPs: 206 (203 → 204 → 205 → 206) [1]

(b)

Work through the operations. The top starts at 202, and a POP moves it down to a higher address; a PUSH moves it up and overwrites that location.

POP → top at 203 ('Y'); POP → top at 204 ('X'); PUSH 'A' → 203 = 'A'; PUSH 'B' → 202 = 'B'; POP → top at 203; PUSH 'C' → 202 = 'C'; PUSH 'D' → 201 = 'D'.

Memory locationValuePointer
200
201'D'TopOfStack
202'C'
203'A'
204'X'
205'Z'
206'N'
207'P'

TopOfStack pointing to 'D' (location 201) [1]

'D' in location 201 [1]

'C' in 202 and 'A' in 203 [1]

'X', 'Z', 'N', 'P' unchanged in 204 to 207 [1]

KEY IDEAA stack is last in, first out: the pointer moves on each PUSH and POP, and popped values are simply overwritten later.
TOTAL 6 marks

Official mark scheme

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

Video solution of the whole paper · by CS BY AQIB KHAN. 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.