Recursion vs Iteration – Difference between Recursion and Iteration

Recursion vs Iteration. What’s the difference between recursion and iteration. Recursion and Iteration both are two different programming approaches. In some cases recursion is best suited and in some other cases iterative way of programming is good.

In programming, repeated set of instructions can be handled either by using recursive or iterative approach in your code. So which approach you choose and why. Let’s talk about recursion vs iteration.

Implementation of Binary Search using Recursion.

Multiply two numbers without using multiplication operator

Recursion vs Iteration

i) In recursion, function call itself until the base condition is reached.

On other hand iteration means repetition of process until the condition fails. For example –  when you use loop (for,while etc.) in your programs.

ii) Iterative approach involves four steps, initialization , condition, execution and  updation.

In recursive function, only base condition (terminate condition) is specified.

iii) Recursion keeps your code short and simple Whereas iterative approach makes your code longer.

iv) Recursion is slower than iteration due to overhead of maintaining stack whereas iteration is faster.

v) Recursion takes more memory than iteration due to overhead of maintaining stack  .

Subscribe Our Tutorials

Get Latest Updates on Facebook

vi) If recursion is not terminated (or base condition is not specified) than it creates stack overflow (where your system runs out of memory).

vii) Any recursive problem can be solved iteratively . But you can’t  solve all problems using recursion.

MCQ on Recursion

Example of Programs using Recursion and Iteration Method

Let’s solved some program using both recursive and iterative approach.

Reverse a linked list using recursion

Print fibonacci series using recursion

i) Find Factorial of a Number using Recursion 

Factorial Program using Iterative Method

ii) Sum of N Natural Numbers using Recursion

Sum of N Natural Numbers using Iteration

Important Points for Recursive and Iterative Approach

1. Recursion keeps your code short and clean as compared to iteration.

2. On other hand Recursion uses more memory than iteration due to excessive use of call stack.

There are some problems which can be efficiently solved using recursion such as

1. Travesals (Tree, Graph search).

2. Sorting algorithms (Merge Sort, Quicksort)

Linked List Problems

For complex problem it is always better to use recursion as it reduces the complexity and keeps code readable as compared to iteration.


Never use recursion for simple programs or programs which are not recursive in nature. Iterative approach is more efficient in terms of memory utilization and speed of execution.


About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , . Bookmark the permalink.