SemSure
←
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).

Opens chatgpt.com in a new tab with a ready-made prompt for this topic.

Watch it on YouTube
2Understand it
long factRec(int n) { if (n <= 1) return 1; return n * factRec(n - 1);}/* Back in main */long factIter(int n) { long f = 1; int i; for (i = 2; i <= n; i++) f *= i; return f;}/* Back in main */Stack · 1 activen = 5runningStack · 1 activeOne frame, updated in placei = — f = 1
Current C line
Recursive calls so far1Loop passes so far0
Step 1 of 15

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.

Try it on paper first. Then check each step.