Recursion Concept with Example

What is recursion and how to use recursion in programming. If you are new to programming, then recursion concept is tough to understand. In this post, i’ll explain the concept of recursion with example.

What is Recursion ?

In Recursion, function call itself repeatedly, until the base or terminating condition is not true. To understand this statement let’s take an example.

Suppose, we have to print a number between start to end range. Let’s print number between 1 to 10.

It’s a much preferred way to write cleaner and shorter code for many complex problems.

Through recursion, you can reduce complex problem into smaller version.

Recursion Objective Questions for Practice.

Recursion vs iteration

Implement Binary Search Algorithm using Recursion.

Explanation of Recursion with Example

i) Factorial problem using recursion

Let’s say, you have passed 0 in factorial function in that case first condition is met and it returns 1.

Now let’s check how it work when 5 is enter .

Program to print Fibonacci series using recursion

Reverse a linked list using recursion

What happens if base condition is not defined in recursive programs.

In that case program will run until the system get out of memory.

Tagged , . Bookmark the permalink.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.