# Recursive Functions

What do you mean by recursive functions?

A function may call itself or other functions, and the called functions in turn may again call the calling function. Such functions are called recursive functions.

Any correct iterative code can be converted into its equivalent recursive code and vice versa.
The basic concepts and ideas involved with recursion are simple - a function that has to be solved is treated as a Big problem and it solves itself by using itself to solve a slightly smaller problem. The recurrence relation is easily converted to recursive code.

Recursion can be used in Divide and conquer based search algorithms to increase the efficiency of these operations.

Binary Recursion: A simple unary recursive function calls itself once, whereas the binary recursive function call itself twice. A factorial is a unary function, whereas Fibonacci is a binary recursion.

Depth of recursion: The number of times a function calls itself is known as the recursive depth of that function.

Direct and Indirect recursion: When a recursive function calls itself directly, it is called direct recursion and when the function calls another function, which in turn calls the first function, it is called an indirect recursion.

End condition: Recursive functions usually have and in fact should have a condition that would terminate the recursive calls. The terminating condition is called end condition. In the function factorial, when n=1 the function returns 1. If this condition were not present, the function would keep calling itself with the values ......., 3, 2, 1, 0, -1, -2, -3, .....  and so on until infinity. Such a recursive function is known as endless recursion.

Thanks
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..