Recursion
with Examples in Java |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
return
Statements in Recursive Methods/Functions
Some people find it easier to understand recursive methods/functions when they
have multiple return
statements.
The public
method does not require the caller to know anything
about the recursion.
The base
attribute is used to keep track of the
base (rather than passing it as a parameter).
An attribute can be used so that the coins
array does not have
to be a parameter of the recursive method.
Is this implementation tail-recursive? In other words, what is the last action performed?
A tail-recursive implementation:
Converting a tail-recursive implementation to an iterative implementation: