int gcd(int x, int y) {
if (x % y == 0) // base case
return y;
else
return gcd(y, x % y);
}
0, 1, 1, 2, 3, 5, 8, 13, ... fib(n)
fib(n) = fib(n-1) + fib(n-2)
Base case: n==0 , n == 1
// algorithm 1: very inefficient
int fib(int n)
{
if (n==0) // base case
return 0;
else if (n==1) //base case
return 1;
else
return fib(n-1) + fib(n-2);
}