Monday, October 12, 2009

Introduction and definition of Recursion

Recursion is a repetitive process in which an algorithm or function calls itself. C & C++ both support recursive programming.

For the definition of function or algorithm not to be circular, it must have the following two properties.

1. There must be certain values, called based values, used for termination of program or definition of function. At these base values the function / algorithm does not call itself.

2. Each time function / program call itself, it must be closer to the base condition.

Some mathematical functions and problems (a few to mention) that can be solved recursively are

· Factorial

· Fibonacci Number

· Euclid GCD

· Towers of Hanoi

· Binary Search

Actually, in programs call stack or stackframes does this housekeeping job. Besides functions, data structures also may be recursively defined. One of the most important class is trees.

No comments:

Post a Comment