Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms

Q24 · 9618/33/O/N/25 Q10

Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2.

Q249618/33/O/N/25original Q10Structured · 6 marks
Question 10 from 9618/33/O/N/25

Worked solution

(a)

Declare a constant for the size, two integer pointers (bottom and top) and a string array of 100 items.

CONSTANT Maximum = 100
DECLARE Base : INTEGER
DECLARE Top : INTEGER
DECLARE StackArray : ARRAY[1:100] OF STRING

Constant Maximum = 100 declared correctly [1]

Both pointers Base and Top declared as INTEGER [1]

Array StackArray declared with 100 elements of type STRING [1]

(b)

Write a procedure that sets both pointers to starting values for an empty stack.

PROCEDURE InitialiseStack()
    Base ← 0
    Top ← 0
ENDPROCEDURE

Correct procedure structure (PROCEDURE ... ENDPROCEDURE) [1]

Base set to a suitable value (0 or 1) [1]

Top set to a suitable value (-1, 0 or 1) [1]

The values must fit the array bounds you declared in part (a).

KEY IDEAA stack needs a constant size, two pointers and an array, and the pointers start at values that mean empty.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/33/O/N/25 question 10
VIDEO
▶ Topic lesson

A lesson on this topic · by rjmcompsci. 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.