Skip to main content
A-LevelComputer ScienceProgramming9618/31 · Oct/Nov 2021 · Q1013 Marks

The function StackFull() checks whether a stack is full. The function uses the variable TopOfStack to represent the pointer to the most recent position used on the stack, and the variable Max to represent the maximum size of the stack. Assume TopOfStack and Max are global variables. FUNCTION StackFull() RETURNS BOOLEAN IF TopOfStack = Max THEN RETURN TRUE ELSE RETURN FALSE ENDIF ENDFUNCTION An algorithm AddInteger is required to add a new integer data element to a stack. The stack is implemented as an array ArrayStack. The function AddInteger() calls StackFull() and returns an appropriate message. Complete the pseudocode for the function AddInteger(). FUNCTION AddInteger(NewInteger : INTEGER) RETURNS STRING ENDFUNCTION

  1. (a)State three essential features of recursion.[3]
  2. (b)Explain the reasons why a stack is a suitable Abstract Data Type (ADT) to implement recursion.[3]
  3. (c)Identify two ADTs other than a stack.[2]
  4. (d)The function StackFull() checks whether a stack is full. The function uses the variable TopOfStack to represent the pointer to the most recent position used on the stack, and the variable Max to represent the maximum size of the stack. Assume TopOfStack and Max are global variables. FUNCTION StackFull() RETURNS BOOLEAN IF TopOfStack = Max THEN RETURN TRUE ELSE RETURN FALSE ENDIF ENDFUNCTION An algorithm AddInteger is required to add a new integer data element to a stack. The stack is implemented as an array ArrayStack. The function AddInteger() calls StackFull() and returns an appropriate message. Complete the pseudocode for the function AddInteger(). FUNCTION AddInteger(NewInteger : INTEGER) RETURNS STRING ENDFUNCTION[5]

Mark scheme

Marking points from the official mark scheme (Oct/Nov 2021). The mark or mark type is shown in brackets.

  1. [3] One mark for each correct marking point (Max 3)
  2. • Must have a base case/stopping condition
  3. • Must have a general case
  4. • ... which calls itself (recursively) // Defined in terms of itself
  5. • ... which changes its state and moves towards the base case
  6. • Unwinding can occur once the base case is reached.
  7. [3] One mark for each correct marking point (Max 3)
  8. • A stack is a LIFO data structure
  9. • Each recursive call is pushed onto the stack
  10. • ... and is then popped as the function ends
  11. • Enables backtracking/unwinding
  12. • to maintain the required order.
  13. [2] One mark for each marking point (Max 2)
  14. • Linked List
  15. • Queue
  16. • Binary Tree
  17. [5] One mark for each marking point (Max 5)
  18. • Checking if stack is full / empty using IF ... THEN ... (ELSE) ... ENDIF
  19. • ... correctly using StackFull() function
  20. • RETURN suitable message if stack is full
  21. • RETURN message if space available on stack
  22. • Incrementing TopOfStack pointer if space available
  23. • Assigning new data using correct NewInteger variable
  24. • ... to correct the array element in ArrayStack[] array.
  25. Example algorithm
  26. FUNCTION AddInteger (NewInteger : INTEGER) RETURNS STRING
  27. IF StackFull() THEN
  28. RETURN "The stack is full"
  29. ELSE
  30. TopOfStack ← TopOfStack + 1
  31. ArrayStack [TopOfStack] ← NewInteger
  32. RETURN "Item added"
  33. ENDIF
  34. ENDFUNCTION

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 →

About this question

Topic
Programming, A-Level Computer Science (syllabus 9618). Structured question, 13 marks.
Source
A-Level Computer Science, Oct/Nov 2021 Paper 3 Variant 1, question 10.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep