Community resourceWorksheet
OCR H446 2.2.1 Recursive functions
Part 3 of 14 · H446 2.2.1 · Programming techniques
Recursion is examined in H446 2.2.1 as a tracing skill and a construction skill at once. This worksheet separates the two directions of a recursive call, the descent into smaller problems and the unwinding of returned values, so students can explain why a function terminates rather than only recognise the pattern.
Students will:
- distinguish the base case from the recursive case in a supplied function
- trace recursive calls alongside the values returned as they unwind
- explain termination and the order in which results are combined
- write a recursive digit sum using remainder and integer division
- repair a recursion that never reaches a base case and justify the repair
Inside: 6 explanation cells, 2 multiple-choice questions, 1 fill-in-the-blanks cell, 2 written answers, 1 Python task and 1 trace table. 18 marks, about 25 to 35 minutes.
Series: H446 2.2.1 · Programming techniques, part 3 of 14.
Shared by Coding PathwayVerified teacher
- 13 cells
- About 30 minutes
- CC BY-SA 4.0
- Shared 31 Aug 2026
- Updated 3 Sept 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Recursive functions
Nested structures and self-similar patterns can be solved by reducing a problem to a smaller version of itself.
By the end, you will be able to
- identify base and recursive cases
- show progress towards termination
- trace calls downward and returns upward
- write and repair a short recursive function
Reactivate: calling a function and using its returned value.
Two cases and two directions
The base case returns a result without another self-call. The recursive case calls the function with a smaller or simpler input. Calls descend until the base case, with each waiting call retaining its own parameter and unfinished work. Returned values then travel back in the opposite direction as the calls unwind.
Do not trace only the downward calls: OCR questions may require the final value, which depends on the return phase.
Before seeing the call-stack model, what must happen when pattern_total(2) needs the result of pattern_total(1)?
- AThe call with 2 finishes before the call with 1 starts.
- BBoth calls share one parameter value.
- CThe base case is skipped.
- DThe call with 2 waits while a new call with 1 is evaluated.
Worked model: calls first, answers later
For total(n), each call with n > 0 waits for total(n − 1). At n = 0 the base case returns immediately. Only then can pending additions finish from the deepest call outward.
Write traces in two phases: descent (parameters and new calls) then unwinding (returned values). A valid recursive case must make measurable progress to the base case.
What is the main purpose of a base case?
- AIt stops further recursive calls for the simplest input.
- BIt makes every call use a loop.
- CIt stores all parameters globally.
- DIt guarantees constant memory use.
Trace the calls and returned values.
Enter a value only when it changes. Keep the listing's order.
Use one row for each pass through the loop. Fill in a box only when that value changes on that row, and leave the rest blank.
def pattern_total(n):if n == 0:return 0return n + pattern_total(n - 1)answer = pattern_total(4)print(answer)
| Row | n (pattern_total) | answer | Return value | Depth | n == 0 | Output |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | ||||||
| 3 | ||||||
| 4 | ||||||
| 5 | ||||||
| 6 | ||||||
| 7 | ||||||
| 8 | ||||||
| 9 | ||||||
| 10 | ||||||
| 11 | ||||||
| 12 |
Explain why pattern_total(4) terminates and state the order in which the additions are completed while calls return.
Refer to the changing parameter and the base case.
Students type their answer here.
Write a recursive digit sum
Return the sum of the decimal digits in a non-negative integer. Use n % 10 for the final digit and n // 10 for the remaining digits.
def digit_sum(n):
# Base case, then recursive case.
passRepair this broken recursion, then explain why your repair terminates: def count_down(n): return [n] + count_down(n - 1). Write a suitable base case and corrected function body.
For n <= 0 the result should be an empty list. Then link decreasing n to the stopping condition.
Students type their answer here.
Checkpoint
Complete the safe-recursion explanation from memory. There is no answer bank, and correctness is withheld until teacher review.
Review your understanding
Before submitting, check that you can explain the main distinction in your own words, apply it in an unfamiliar context and justify the resulting behaviour or consequence.