---
title: "Recursion versus iteration"
subject: "Computer Programming"
chapter: 6
key: "semester_1/computer_programming:recursion-vs-iteration"
source: https://www.bctengineer.com/q/semester_1/computer_programming/recursion-vs-iteration
site: BCT Engineering
---

# Recursion versus iteration

Computer Programming · Chapter 6: User-Defined Functions

- Asked in: 2067 Asoj, 1 marks
- Video: [C programming # difference between iteration and recursion.](https://www.youtube.com/watch?v=vf-MQMXjT5c) — Bikram Panthee
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/recursion-vs-iteration
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-6

## Question

How is recursion different from iteration?

## Short answer

Recursion divides the problem via self-calls with a base case, using extra stack memory and being slower. Iteration repeats statements with loops, using constant memory and executing faster. Both yield the same results.

## Answer

Recursion solves a problem by a function calling itself on smaller inputs, whereas iteration repeats a block of statements using loops (`for`, `while`). Recursion uses more memory (a stack frame per call) and is usually slower, but is shorter for naturally recursive problems; iteration uses less memory and is faster. Both compute the same results:
```c
#include <stdio.h>
int sum_rec(int n) { return n == 0 ? 0 : n + sum_rec(n - 1); }
int sum_iter(int n)
{
    int i, s = 0;
    for (i = 1; i <= n; i++)
        s += i;
    return s;
}
int main(void)
{
    printf("%d %d\n", sum_rec(5), sum_iter(5));
    return 0;
}
```
Output:
```text
15 15
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Recursion is?
   A. Loops
   B. Function calling itself
   C. Pointers
   D. Arrays
   Answer: B. Definition. (Key point: Recursion)

2. Which uses more memory?
   A. Iteration
   B. Same
   C. Recursion (stack frames)
   D. Neither
   Answer: C. Frame per call. (Key point: Memory)

3. Which is usually faster?
   A. Recursion
   B. Same
   C. Random
   D. Iteration
   Answer: D. Less overhead. (Key point: Speed)
