Importance Of Recursive Functions

Recursion: It is a special case of process, where a function calls itself. 

A function is called recursive if a statement within the body of a function calls the same function. Recursive functions allow programmers to write efficient codes using a minimal amount of code. Recursion is very important because it often allows a breathtakingly simple algorithm solution to certain problems that would be otherwise practically unobtainable with an iterative algorithm.

Recursive thinking is very important in programming. When writing recursive functions, you must have an if statement somewhere in the recursive function to force the function to return without a recursive call being executed. If you do not do this and call the function, you will fall in an indefinite loop and never return from the called function.
Recursion is three types:

1) Linear Recursion: Linear recursion is the simplest form, where a method is defined as it makes at most one recursive call each time it is invoked. This is useful when we view an algorithm problem in terms of the first or last element plus a remaining set with the same structure as the original set.

2) Binary Recursion: Binary recursion occurs whenever there are two recursive calls for each non-base case. These two calls can be used to solve two identical halves of some problems.

3) Tail Recursion: Tail recursion can easily be replaced by iterative code. The reverse Array algorithm is an example of tail recursion. So if it is tail recursion, then storing addresses into a stack is not needed. It is equivalent to iteration.

Limitations of Recursion :

> Reduce unnecessary calling of function. 
> Though recursion, we can quickly solve problems while its iterative solution is very big and complex.
> recursive solution is always logical and difficult to debug.
> Recursion uses more processor time.
> Recursion takes lots of stack space.
> The computer may run out of memory if the recursive calls are not properly checked.

Maroju Sanjana

Categories: News