9618/32/O/N/25 question 12: worked solution (October/November 2025, paper 32)
Show as plain textHide plain text
Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2. Q23 9618/32/O/N/25 original Q12 Structured · 9 marks Worked solution (a)(i) Fill in the four gaps. The parameter is the new item, a string. Top goes up by 1 before the item is stored. If the stack is full, output a message. PROCEDURE Push(NewData : STRING) IF Top < Max - 1 THEN Top ← Top + 1 StackArray[Top] ← NewData ELSE OUTPUT "Stack full; new data cannot be added" ENDIF ENDPROCEDURE Parameter written as NewData : STRING [1] Top ← Top + 1 [1] StackArray[Top] ← NewData [1] OUTPUT of a suitable error message such as "Stack full" [1] (a)(ii) Input the item into a variable, then call Push with that same variable. INPUT MyData CALL Push(MyData) INPUT into a variable (a prompt is optional) [1] CALL Push with the input variable as the parameter [1] (b) A stack is Last In First Out (LIFO) , so the last item stored is the first one taken off. [1] Each time the recursive algorithm calls itself , data (such as the return address and parameters) is pushed onto the stack. [1] When the base case is reached, the calls start to unwind and the data is popped in the reverse order to which it was pushed. [1] KEY IDEA A stack holds the data of each recursive call and gives it back in reverse order as the calls unwind. TOTAL 9 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.