What is Recursion?
In programming, recursion is a method in which a function calls
itself a specified number of times to achieve the desired output.
This implementation is known as Recursion whereas the function is
called Recursive function and the call is called Recursive call.
Example Fibonacci series problem, finding largest number in an
Array, Factorial of a Number, etc.
Types of Recursion in C++
- Single or Linear
Recursion: In this type of recursion, function calls itself
only once in a single call during the execution. Problems that need
to implement only a single recursive call in the recursive function
can be classified as a Single Recursion problem. Example, Factorial
of a number (Please see the program below for better understanding)
- Binary
Recursion: In this type of recursion, function calls itself
twice in a single call during the execution. Problems that need to
implement two recursive calls in the recursive function can be
classified as a Binary Recursion problem. Example, Fibonacci Series
(Please see the program below for better understanding)
- Multiple
Recursion: This can be considered as a generalized form of
the Binary recursion where function calls itself multiple times
(two or more) in different calls during the execution. Problems
that need to implement more than two recursive calls in the
recursive function can be classified as a Multiple Recursion
problem. Example, Tower of Hanoi