Computer Science Notes

Notes From CS Undergrad Courses FSU

This project is maintained by awa03

Basic Rules for a recursive function

1) Base Case: must always have a base case in order to make a recursive call 2) Must stop at some point

Examples

Fibonacci

$$ fib_n=fib_{n-1}+fib_{n-2} $$

int sum(A,n)   // finds the sum of n elements

// Recursive Example
int sum(A,n){
	if(n==0) return 0;
	return sum(A, n-1) + A[n-1];
}

#cpp #code #recursion #functions