9618/23/O/N/25 question 3: worked solution (October/November 2025, paper 23)

Show as plain text

Cambridge AS Level Computer Science 9618 · 10.4 Introduction to Abstract Data Types (ADT) Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 4 of 4. Q85 9618/23/O/N/25 original Q3 Structured · 5 marks Worked solution (a) The stack pointer SP holds the index of the top item, and 0 means empty. So the stack is empty when SP is less than 1. Otherwise take the item at ThisStack[SP], then lower SP by 1. Write these in the blanks: FUNCTION Pop() RETURNS PopData DECLARE ThisPop : PopData IF SP < 1 THEN PopData.Exists ← FALSE // Stack is empty ELSE PopData.Data ← ThisStack[SP] PopData.Exists ← TRUE SP ← SP - 1 ENDIF RETURN ThisPop ENDFUNCTION DECLARE ThisPop : PopData (the local variable has the type the function returns) [1] IF SP < 1 THEN (also accepted: SP = 0) [1] Write FALSE after PopData.Exists in the empty branch and TRUE after PopData.Exists in the ELSE branch. Both must be right [1] PopData.Data ← ThisStack[SP] [1] SP ← SP - 1 [1] KEY IDEA To pop, test for an empty stack first, then read the top item at SP and decrease SP by 1. TOTAL 5 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Papersdock . Tap the picture to open it on YouTube.