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

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. Q76 9618/21/O/N/23 original Q3 Structured · 8 marks Worked solution (a) The array is filled from element 1 upwards, so the bottom item D2 goes in element 1. Array element Data 8 7 6 5 D1 4 D3 3 D4 2 D5 1 D2 Variable Value TopOfStack 5 BottomOfStack 1 All values in the order and places shown [1] TopOfStack = 5 (the element holding D1) [1] BottomOfStack = 1 (the element holding D2) [1] (b) Complete the five steps: 1 If TopOfStack = 8 (the stack is full ) then return FALSE [1] 2 Otherwise increment TopOfStack [1] 3 Use TopOfStack as an index to the array [1] 4 Set the element at this index (location or position) to the value (data or item) being added [1] 5 Return TRUE [1] KEY IDEA A stack in an array uses a top index: check for full, move the index up, store the value, return TRUE. TOTAL 8 marks Official mark scheme VIDEO ▶ Starts at Q3 (15:42) Starts at Q3 (15:42) · by Pseudocode Pro. Tap the picture to open it on YouTube.