Introduction to Recursion

Recursion ?

Recursion means recursion. 🙂

Google explains Recursion in there way, just try searching recursion and see what happens :


So you got the idea now that recursion has something to do with Repetition. Let’s first go throw the formal definition of recursion from Wikipedia :

Recursion is the process of repeating items in a self-similar way.

Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem (as opposed to iteration).[1] The approach can be applied to many types of problems, and recursion is one of the central ideas of computer science.[2] – Wikipedia

In programming Language recursive method is the one which calls it self. For example consider the following example :

The above code has a method called Recursion(int x)  that takes integer x as an argument. This method prints the string “Recursing” x times. I will show you what exactly happens in the stack when you write the above code.

Whenever you call a function, it is added to the call stack. The Function last added to call stack is executed first.

For above code, we will start from main :