---
title: "Recursion; iterative vs recursive choice"
subject: "Data Structure and Algorithm"
chapter: 5
key: "semester_4/data_structure_and_algorithm:define-recursion-iterative-vs-recursive"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/define-recursion-iterative-vs-recursive
site: BCT Engineering
---

# Recursion; iterative vs recursive choice

Data Structure and Algorithm · Chapter 5: Recursion

- Asked in: 2072 Magh, 1+2 marks
- Video: [Comparing Iterative and Recursive Factorial Functions](https://www.youtube.com/watch?v=kx6DfrYfWnQ) — Khan Academy
- 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/define-recursion-iterative-vs-recursive
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-5

## Question

Define a recursion. Which algorithm would you prefer between iterative and recursion?

## Short answer

Recursion is a technique where a function calls itself to solve smaller instances of a problem until a base case. Prefer iteration for simple repetitive tasks (factorial, Fibonaci) due to speed and memory; prefer recursion for naturally recursive problems like tree traversal or Tower of Hanoi for clarity.

## Answer

**Recursion** is a technique in which a function calls itself (directly or through another function) to solve a problem by reducing it to smaller instances of the same problem, until a simple base case is reached. Example: `fact(n) = n × fact(n-1)`, `fact(0) = 1`.

#### Which is preferred?
It depends on the problem.
- **Prefer iteration** when a simple loop solves the problem (factorial, Fibonacci, sum of numbers): it is faster, uses constant extra memory and avoids stack overflow. For Fibonacci the recursive version repeats work and makes an exponential number of calls (O(2ⁿ)), while the loop takes n steps.
- **Prefer recursion** when the problem is naturally recursive and the iterative form is complex: Tower of Hanoi, tree traversals, divide-and-conquer sorting (quick sort, merge sort), backtracking.

So for ordinary repetitive tasks I prefer the iterative algorithm; for hierarchical or divide-and-conquer problems recursion gives shorter and clearer code.

## Check yourself

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

1. What is recursion?
   A. A loop that repeats using a counter
   B. Calling functions from main only
   C. A function calling itself to solve smaller instances until a base case
   D. Sorting data in memory
   Answer: C. Recursion reduces a problem to smaller instances of itself with a base case. (Key point: Definition)

2. For which problem is the iterative form preferred?
   A. Tower of Hanoi
   B. Tree traversal
   C. Quick sort
   D. Fibonacci, because recursion repeats work exponentially
   Answer: D. Iteration takes n steps with constant memory while recursion makes about 2^n calls. (Key point: Prefer iteration)

3. When is recursion preferred?
   A. When the problem is naturally recursive and the iterative form is complex
   B. For all simple loops
   C. When memory is very small
   D. When the base case is missing
   Answer: A. TOH, tree traversals and divide-and-conquer give shorter, clearer recursive code. (Key point: Prefer recursion)

## Related in Data Structure and Algorithm

- [Is recursion slow; recursive vs non-recursive](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Arecursion-slow-compare) — Data Structure and Algorithm, chapter 5
- [Prefer O(n) or O(log n) algorithm](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aprefer-on-or-ologn) — Data Structure and Algorithm, chapter 9
- [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
- [TOH algorithm and recursion tree](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Atoh-algorithm-recursion-tree) — Data Structure and Algorithm, chapter 5, asked 2×
- [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

## Related in other subjects

- [Recursive/iterative query and DNS records](https://www.bctengineer.com/question.md?key=semester_7%2Fcomputer_networks_and_security%3Adns-recursive-iterative-records) — Computer Networks and Security, chapter 6
- [When to prefer lag/lead or PID controllers](https://www.bctengineer.com/question.md?key=semester_6%2Fdigital_control_system%3Alag-lead-vs-pid) — Digital Control System, chapter 4
- [Iterative and incremental model](https://www.bctengineer.com/question.md?key=semester_7%2Fict_project_management%3Aiterative-incremental-model) — ICT Project Management, chapter 4
- [Centralized vs Ricart-Agrawala algorithm](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Acentral-vs-ra-compare) — Distributed System, chapter 6
