Programming for Problem Solving · Unit 4: Nested loops, 2-D arrays, recursion vs iteration
Recursion vs iteration: calls, loops and stack memory
BL 4 · AnalyseNew in R2026New in R2026 · CLO-4 says 'Analyze'
✓ 0/5
1What is it
Any repetition can be written with a loop (iteration) or a function that calls itself (recursion). Recursion is shorter for some problems but every call takes a stack frame; a loop reuses the same variables.
Remember
Recursive factorial(n): n calls, n stack frames. Iterative: n − 1 loop passes, 1 frame. Naive recursive fib(n): calls grow roughly 1.6ⁿ (fib(10) needs 177 calls).
Recursion — Push a frame for n = 5. Loop — Start the accumulator at 1.
3Solve a practice question
Syllabus guided practice · count calls vs iterations10 marksBL 4 · Analyse
Compute factorial and Fibonacci recursively and iteratively. Print the number of recursive calls and loop iterations, and evaluate the memory used by each approach.
Try it on paper first. Then check each step.
4Solve a practice question
Syllabus guided practice · binary search both ways10 marksBL 4 · Analyse
Implement binary search using recursion and using iteration on a sorted array. Print the total recursive calls and the total loop iterations.