Recursion is a powerful algorithmic technique in which a function calls
itself (either directly or indirectly) on a smaller problem of the same
type in order to simplify the problem to a solvable state.
Every recursive function must have at least two cases: the recursive case
and the base case. The base case is a small problem that we know how to
solve and is the case that causes the recursion to end. The recursive case
is the more general case of the problem we're trying to solve. As an
example, with the factorial function n!, the recursive case is
n! = n*(n - 1)! and the base case is n = 1 when n = = 0 or n = = 1.
Recursive techniques can often present simple and elegant solutions to
problems. However, they are not always the most efficient. Recursive
functions often use a good deal of memory and stack space during their
operation. The stack space is the memory set aside for a program to
use to keep track of all of the functions and their local states
currently in the middle of execution. Because they are easy to implement
but relatively inefficient, recursive solutions are often best used
in cases where development time is a significant concern.
There are many different kinds of recursion, such as linear, tail, binary,
nested, and mutual. All of these will be examined.