Factorial
A classic example of a recursive procedure is the function used to calculate the factorial of a natural number:
Pseudocode (recursive): |
---|
function factorial is: |
The function can also be written as a recurrence relation:
- $$b_n=nb_{n-1}$$
This evaluation of the recurrence relation demonstrates the computation that would be performed in evaluating the pseudocode above:
Computing the recurrence relation for n = 4: |
---|
b4 = 4 * b3
|