Solving the complex problems using Recursion in C

             Another important area where functions are used is recursion. Recursion is a repetitive process here  a function calls itself.That is in a recursive process a function is calls it self. Recursion is a very important application in every where, including real life also.


             For Example if you observed in a screen recording, where a smaller window is appear as multiple windows. Like below.

Recursion in a screen recording program, where the smaller window contains a snapshot of the entire screen


               The same thing is also useful while solving a complex problem in computer science. Using the recursion the larger problem can be defined in two cases first base case and second general case. In base case the solution to the complex problem is simple and it can be solved easily. But in the general case the complex problem is divided into Small units until we reach the base case condition. Here is best example for recursion how to find factorial of a number using recursion.
The factorial of a given number is computed as using recursion is 
factorial(0) = 1;
factorial(n) =n*(n-1)*(n-2)*(n-3)...............*1
       In the piece of  code the first line is the base case and the second line is the general case. In the first line the solution is comes directly, where as in the second line, the problem is reduced until the base case solution is appeared. This type of solving a problem is known as recursion. They are so may types of recursions among those the two most important are binary recursion and tailor recursion which are examined in the next post.
 

No comments: