![]() |
![]() |
![]() |
![]() |
![]() |
|
The following diagram shows rabbits and its two auxiliaries working
to determine how many Fibonacci rabbits there are at the end of 3 months:
Arguments | ^ Returned values
3 v | 3
*-------------*
| rabbits |
*-------------*
| ^ | ^
3 | | 3 | *------------*
| | *-------------* |
v | 2 v | 1
*-------------* *-------------*
| previous | | penultimate |
*-------------* *-------------*
2 | ^ 1 | ^
v | 2 v | 1
*-------------* *-------------*
| rabbits | | rabbits |
*-------------* *-------------*
| ^ | ^
2 | | 2 | *------------*
| | *-------------* |
v | 1 v | 1
*-------------* *-------------*
| previous | | penultimate |
*-------------* *-------------*
1 | ^ 0 | ^
v | 1 v | 1
*-------------* *-------------*
| rabbits | | rabbits |
*-------------* *-------------*
Each of the three cooperating methods can initiate a chain of calls that ends in a call to itself. Thus, the cooperating methods exhibit indirect, rather than direct, recursion.