9618/31 October/November 2021 · Question 10(a) and (b) · 6 marks
(a) State three essential features of recursion. (b) Explain the reasons why a stack is a suitable Abstract Data Type (ADT) to implement recursion.
Points that gain marks
- There must be a base case (a stopping condition).
- There must be a general case, which calls itself (is defined in terms of itself) …
- … and changes its state so it moves towards the base case. Unwinding happens once the base case is reached.
- A stack is a LIFO data structure.
- Each recursive call is pushed onto the stack, and popped when that call ends.
- This allows the unwinding (backtracking) in the right order.
In this lab: Every level shows the stack: a frame is pushed at each call and popped at each return, last in, first out.