1. Home
  2. Computing & Technology
  3. C / C++ / C#

Definition of Recursion

By David Bolton, About.com

Definition: Functions are recursive if they call themselves. For this to work, the following conditions apply :
  • There must be a solveable problem.
  • There must be a terminating clause.

Factorials are often cited as a classic example of using recursion.

The factorial f(n) = n * (n-1) * (n-2) * .. 1.

For example factorial 5 (written as 5!) = 5 x 4 x 3 x 2 x 1 = 120. The function below returns the factorial of the parameter n.

int factorial( int n) {
if (n==1)
return 1
else
return n* factorial( n-1) ;
}

int value=factorial(6) ;

Glossary:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Examples:
The Eight Queens chess problem can be solved by recursion.

A classic, albeit not very funny definition of recursion is given as a dictionary entry :

Recursion [n] : See Recursion.

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. Glossary
  5. Recursion - Definition

©2009 About.com, a part of The New York Times Company.

All rights reserved.