---
title: "Is recursion slow; recursive vs non-recursive"
subject: "Data Structure and Algorithm"
chapter: 5
key: "semester_4/data_structure_and_algorithm:recursion-slow-compare"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/recursion-slow-compare
site: BCT Engineering
---

# Is recursion slow; recursive vs non-recursive

Data Structure and Algorithm · Chapter 5: Recursion

- Asked in: 2072 Asoj, 1+2 marks
- Video: [Why Simpler Recursive Code Can Be Slower Than Iterative Solutions](https://www.youtube.com/watch?v=picVmuY_1lY) — The Debug Zone
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/recursion-slow-compare
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-5

## Question

Do you think recursive function is slow? Compare recursive and non-recursive functions.

## Short answer

Yes, recursion is generally slower than iteration because each call creates and destroys a stack frame, adding overhead. Some recursions (like naive Fibonaci) suffer from repeated subproblems, causing exponential time. However, for naturally recursive problems like tree traversal or Tower of Hanoi, recursion yields clearer code.

## Answer

#### Is recursion slow?
Yes, generally a recursive function is slower than the equivalent loop, because every call needs time to create and destroy a stack frame (pass arguments, save return address) and uses extra stack memory. Some recursive algorithms (naive Fibonacci) are far slower because they repeat the same sub-problems: fib(30) makes 2,692,537 calls (counted by program) whereas a loop needs 30 steps.

#### Recursive vs non-recursive
| Recursive | Non-recursive (iterative) |
|---|---|
| Function calls itself | Uses loops |
| Needs base case | Needs a loop condition |
| More memory (stack frames) | Less memory |
| Slower due to call overhead | Faster |
| Short, easy to write for naturally recursive problems (TOH, tree traversal) | Longer or harder for such problems |
| Risk of stack overflow | No such risk |

## Check yourself

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

1. Why is recursion generally slower than the equivalent loop?
   A. The CPU cannot run recursive code
   B. Recursion uses no memory
   C. Each call has overhead of creating and destroying a stack frame
   D. Loops are executed in parallel
   Answer: C. Passing arguments, saving return address and frame setup cost time and stack memory. (Key point: Why slower)

2. Why is naive recursive Fibonacci far slower than a loop?
   A. It uses floating point
   B. It has no base case
   C. It sorts values first
   D. It repeats the same sub-problems, so calls grow exponentially
   Answer: D. fib(30) makes about 2.7 million calls while a loop needs 30 steps. (Key point: Naive Fibonacci)

3. When is recursion still preferred?
   A. For naturally recursive problems like TOH and tree traversal where it is shorter and clearer
   B. Whenever speed matters most
   C. For simple sums
   D. Never
   Answer: A. Code is short and readable for such problems despite overhead. (Key point: Recursion strengths)

4. Which statement about recursive vs iterative is correct?
   A. Iterative has stack overflow risk; recursive does not
   B. Recursive has stack overflow risk; iterative does not
   C. Both use the same memory
   D. Neither can fail
   Answer: B. Deep recursion exhausts the stack, while loops use constant extra memory. (Key point: Stack overflow risk)

## Related in Data Structure and Algorithm

- [Recursion; iterative vs recursive choice](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Adefine-recursion-iterative-vs-recursive) — Data Structure and Algorithm, chapter 5
- [Normal vs recursive function](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Anormal-vs-recursive-function) — Data Structure and Algorithm, chapter 5
- [Tail and non-tail recursion](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Atail-vs-nontail-recursion) — Data Structure and Algorithm, chapter 5
- [Define recursion; direct vs indirect](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Adefine-recursion-direct-indirect) — Data Structure and Algorithm, chapter 5
- [Recursion, Fibonacci and TOH](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Arecursion-fibonacci-toh) — Data Structure and Algorithm, chapter 5
- [Recursion properties, Fibonacci, TOH algorithm](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Arecursion-properties-fibonacci-toh) — Data Structure and Algorithm, chapter 5

## Related in other subjects

- [Recursive function and how it works](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Arecursive-function-explain) — Computer Programming, chapter 6, asked 3×
- [Overloading via member and non-member function](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Amember-vs-nonmember-overload) — Object Oriented Programming, chapter 5
- [Compare two strings with function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astring-compare-function) — Computer Programming, chapter 7
- [Unique vs non-unique address decoding](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Aunique-vs-nonunique-decoding) — Instrumentation II, chapter 2
