I have been working on understanding recursion as applies to some examples like Fibonacci and also an Additive Sequence like the one below..
int AdditiveSequence(int n, int t0, int t1){
if(n == 0) return t0;
if(n == 1) return t1;
return AdditiveSequence(n - 1, t1, t0 + t1);
}
I thought about how it could apply and tried this:
static final double PERCENT = 0.005;
double Depreciation(int month, double currentValue){
if(month == 0)return currentValue;
return Depreciation(month - 1, currentValue -= currentValue * PERCENT);
}
But this does not seem to be a recursion and more like an iteration as when I view in Eclipse debug screen it exits on month == 0 with the iterated currentValue
being returned correctly.
In the case of the Factorial(n) method:
int Factorial(f){
if(f == 1){
return 1;
}else{
return f * Factorial(f - 1);
}
}
It seems to defer computation until the base case is reached and then return back down the stack until the result is reached...
Can anyone help me identify what I have done with the above Depreciation method and if it is in fact recursion or iteration.