3 The diagram represents an Abstract Data Type (ADT). The operation of this stack may be summarised as follows: : The TopOfStack pointer points to the last item added to the stack. The BottomOfStack pointer points to the first item on the stack. Stack D1 TopOfStack D3 D4 D5 D2 BottomOfStack
- (a)The stack is implemented using two variables and a 1D array of 8 elements as shown. The variables are used to reference individual elements of the array, in such a way that: : the array is filled from the lowest indexed element towards the highest all the elements of the array are available for the stack. Complete the diagram to represent the state of the stack as shown above. Array element Data 8 7 6 5 4 3 2 1 Variable TopOfStack BottomOfStack[3]
- (b)A function Push() will add a value onto the stack by manipulating the array and variables in part (a). Before adding a value onto the stack, the algorithm will check that space is available. If the value is added to the stack, the function will return TRUE, otherwise it will return FALSE. The algorithm is expressed in five steps. Complete the steps. 1. If 2. Otherwise 3. Use TopOfStack as an 4. Set the element at this 5. Return then return FALSE TopOfStack to the array. to the being added.[5]
This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2023). The mark or mark type is shown in brackets.
- [1] All values (D1, D3, D4, D5, D2) in the order shown (Array element 5=D1, 4=D3, 3=D4, 2=D5, 1=D2)
- [1] TopOfStack value is 5 (index of element containing D1)
- [1] BottomOfStack value is 1 (index of element containing D2)
- [1] If TopOfStack = 8 then return FALSE
- [1] Otherwise, increment TopOfStack
- [1] Use TopOfStack as an index to the array.
- [1] Set the element at this index / location / position to the value / data / item being added.
- [1] Return TRUE
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →