About Me

Hello there! Before talking about qualifications and professional abilities, I would like to introduce myself. I am a Yuvraj Basnet and professional software developer and have been working in this field for 3 long years. I have finished my graduation from The University of Delhi on Computer Science Engineering I considered myself a reasonably experienced programmer with a particular interest in the human side of software development, computers are fascinating machine, but they're mostly reflection of the people using them. In the art of software development, studying code isn't enough; you have to study the people behind the software, too.

What is Recursion

In the previous article we discussed some important programs and now I will explain
You the most important topic of C language
 i.e, Recursion

What-is-recursion

What is Recursion ?
A function that call itself is known as Recursion function.

Recursion is a process of repeating items in a self similar way.
If a program allow you to call a function inside the same function then it is know as recursive call of the function.

Sample code of Recursion :

What-is-recursion

Advantages of Recursion
1. The main advantage of recursion to algorithm design is that it allows coders to take benefit of the repetitive statements present in many problems.

2. Complex nested loops and case analysis can be avoided.

3. Recursion can lead to more readable , understandable and efficient algorithm description.

4. Recursion is also a useful way for defining objects that have a repeated similar structure form.

Disadvantages of Recursion
1. Can cause infinite loops and other unexpected results if not written properly.

2. If the end condition is not defined then the recursion will repeat forever. Causing the program to crash.

3. Decreasing execution time and storing on the run-time stack more things than require in a non recursive approach.

4. Even if some recursive function repeats the computation for some parameters, the run-time can be prohibitively long even for very simple basic cases.

Types of recursion 

A function is call recursive if it makes a call to itself directly, indirectly. If a function funct() calls itself within the function, it is called recursive.
If a function funct() calls another function fun() that ultimately call back to function() , then it also considered as a recursive function.

1. Direct Recursion
A recursive function is called direct recursion if it call the same function. The factorial is a good example of direct recursion.

STRUCTURE

2. Indirect Recursion
A function (funct) is called indirect recursive if it calls another function(funct1) and then funct1 calls funct directly or indirectly.

STRUCTURE

3. Tail Recursion
A function is said to be tail recursive if the recursive call is the last thing done by the function. There is no need to keep record of the previous state.

STRUCTURE
Output- 3 2 1

4. Non-Tail Recursion 
A function is said to be tail recursive if the recursive call is not the last thing done by the function. After return back, there is some something left to evaluate.

STRUCTURE
Output- 1 2 3


















Post a Comment

0 Comments