Cambridge A2 Level Computer Science 9618 · 19.2 Recursion

Q25 · 9618/31/M/J/23 Q12

Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 2 of 2.

Q259618/31/M/J/23original Q12Structured · 7 marks
Question 12 from 9618/31/M/J/23

Worked solution

(a)

Write any two of these:

Recursion is a process where a function or procedure is defined in terms of itself (it calls itself) [1]

It needs a base case (a way to return without making a recursive call) [1]

Other points that also score: there must also be a general case where the recursive call happens.

(b)

Calls go down until Number is 0 or 1 (the base case), then answers are added back up (unwinding).

Call numberFunction callNumberResultReturn value
1Fib(5)5Fib(4) + Fib(3)
2Fib(4)4Fib(3) + Fib(2)
3Fib(3)3Fib(2) + Fib(1)
4Fib(2)2Fib(1) + Fib(0)
5Fib(1)111
6Fib(0)000
(4)Fib(2)21 + 01
(3)Fib(3)31 + 12
(2)Fib(4)42 + 13
(1)Fib(5)53 + 25

Call number column correct [1]

Function call and Number columns correct [1]

Result column correct going down to the base case (rows 1 to 6) [1]

Result column correct coming back up (rows 7 to 10) [1]

Return value column correct, ending with 5 [1]

KEY IDEAA recursive function stops at a base case, then each earlier call finishes in reverse order using the returned values.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/31/M/J/23 question 12
VIDEO
▶ Whole paper

Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.