Recursion

From GPWiki
Jump to: navigation, search

The term recursion in programming may refer to the effect of any procedure that calls itself within its own definition i.e. a recursive algorithm. Effectively, a recursive algorithm may be considered a natural loop in the sense that it independently re-executes to an uncertain order by literally referring to itself. For instance, recursion may be employed as a natural method to enumerate hierarchical populations of data such as a bone hierarchy used in the practice of dynamic animation.

For example, a C function to compute partial sums of the Fibonacci series may be implemented by literally defining a function that refers to itself, which explicitly exhibits the recurrence relation:

unsigned int FibonacciRecursive(unsigned int partialSumIndex)
{
	if (partialSumIndex > 1)
	{
		return FibonacciRecursive(partialSumIndex-1) + FibonacciRecursive(partialSumIndex-2);
	}
 
	return 1;
}


40px-sprout.png   This article is a stub. You can help out by expanding it.