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: 7 explanation cells, 2 multiple-choice questions, 1 fill-in-the-blanks cell, 2 written answers, 1 Python task and 1 trace table. 19 marks, about 40 to 55 minutes.
Series: H446 2.2.1 · Programming techniques, part 3 of 14.
Shared by Coding PathwayVerified teacher
- 14 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 31 Aug 2026
- Updated 1 Oct 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Recursive functions
A recursive function calls itself to solve a smaller or simpler version of the same problem. It needs a stopping condition, usually called the base case, and each new call must move towards it. Recursion is useful for structures such as nested folders, trees and menus.
By the end, you will be able to
- identify a base case and a recursive case
- explain how an input moves towards the base case
- trace new calls on the way down and returned values on the way back
- write and repair a short recursive function
Predict before the model
Read the question below before viewing the call-stack diagram. Treat each function call as a separate invocation with its own parameter value. Decide whether the current call can finish before the returned value from the smaller call is available.
When pattern_total(2) needs the result of pattern_total(1), what must happen?
- 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.
Two cases and two directions
A recursive function needs two connected parts:
- the base case handles the simplest input, returns a value without making another recursive call, and starts the return phase;
- the recursive case changes the input and calls the function again, making measurable progress towards the base case.
Calls are created on the way down. Each waiting call has a call-stack frame that keeps its parameter, local variables, return address and unfinished calculation. When the base case returns, those waiting calls complete in reverse order as the results unwind. A base case that is never reached does not prevent infinite recursion.
Worked trace: calls first, answers later
For pattern_total(3), do not jump straight to 6. Record the two phases separately.
Calls descend
pattern_total(3) waits for pattern_total(2)
pattern_total(2) waits for pattern_total(1)
pattern_total(1) waits for pattern_total(0)
pattern_total(0) returns 0 without another call
Results unwind
pattern_total(1) returns 1 + 0 = 1
pattern_total(2) returns 2 + 1 = 3
pattern_total(3) returns 3 + 3 = 6
The base case does more than 'end the program': it prevents another self-call for the simplest input and provides the first value used while earlier calls return.
What does the base case do when its condition is met?
- 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. Then state the order in which values are returned while the waiting calls unwind.
Connect the changing parameter to the base case, then describe the return phase separately.
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 version terminates: def count_down(n): return [n] + count_down(n - 1). For n <= 0, the result should be an empty list.
Write the complete two-case function. Your explanation must identify progress and the point at which no further self-call is made.
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.