- Recursive algorithm: Has two parts (a) base case and (b)
smaller instances of itself .
- A recursive step includes a return statement
public static long factorial(long number) { if(number <=1)
// test base case {
return 1;
} else { // test recursive return number * factorial(number-1); } }
- If the recursive call occurs at the beginning of a method, it is
called a head recursion. Head Recursion: A call is head-recursive
when the first statement of the function is the recursive call
|