A stack Abstract Data Type (ADT) is to be implemented using pseudocode, with procedures to initialise it and to push new items onto the stack. A 1D array Stack stores the contents of the stack.
- (a)(i)Study the pseudocode in part (a)(ii) and complete the table of identifiers by writing the missing data types and descriptions. [Figure X.X][2]
- (a)(ii)Complete the pseudocode. CONSTANT MaxSize = 40 DECLARE BasePointer : INTEGER DECLARE TopPointer : INTEGER DECLARE Stack : ARRAY[1:40] OF REAL // initialisation of stack PROCEDURE Initialise() ENDPROCEDURE 1 0 // push an item onto the stack PROCEDURE Push(NewItem : REAL) MaxSize THEN Stack [TopPointer] ENDIF ENDPROCEDURE[5]
- (b)Justify the use of a linked list instead of an array to implement a stack.[2]
- (c)Explain how a compiler makes use of a stack when translating recursive programming code.[4]
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] BasePointer: INTEGER, Points to the bottom of the stack
- [1] TopPointer: INTEGER, Points to the top of the stack
- [1] Stack: REAL, List of decimal numbers stored in the stack
- [1] BasePointer ← 1
- [1] TopPointer ← 0
- [1] IF TopPointer < MaxSize THEN
- [1] TopPointer ← TopPointer + 1
- [1] Stack[TopPointer] ← NewItem
- [1] A linked list is a dynamic data structure / not restricted in size
- [1] Has greater freedom to expand or contract by adding or removing nodes as necessary
- [1] Allows more efficient editing using pointers (instead of moving the data).
- [1] An array is a static data structure1 generally fixed in size
- [1] When the array is full, the stack cannot be extended any further.
- [1] The compiler must produce object code to
- [1] ...push return addresses / values of local variables onto a stack
- [1] ...with each recursive call // ... to set up winding
- [1] ...pop return addresses / values of local variables off the stack ...
- [1] ...after the base case is reached // ... to implement unwinding.
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 →