UMBC CS 201,Spring 04
UMBC CMSC 201 Spring '04 CSEE | 201 | 201 S'04 | lectures | news | help

Recursion

Definition

Recursion in Mathematics

A recursive definition is one which refers to itself as in these definitions of the factorial and fibonacci functions.

n! or fact(n) is defined as:

     fact(0) = 1  
     fact(n) = n*fact(n-1) , for  n > 0

the nth fibonacci number or fib(n) is defined as:

     fib(0) = 1
     fib(1) = 1
     fib(n) = fib(n-1) + fib(n-2) , for  n > 1 

Recursion in Programs

A recursive function is a function that calls itself.

factorial function in C

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






CSEE | 201 | 201 S'04 | lectures | news | help

Tuesday, 20-Jan-2004 13:49:20 EST