I'm given a function:
int fib(int n) {
if (n == 0 || n == 1) return n;
return fib(n - 1) + fib(n - 2);
}
from which I am supposed to determine a function of n that expresses the number of additions performed.
Running this through some inputs, I see a pattern:
$$ \begin{array}{c|lcr} n & \text{Additions} \\ \hline 1 & 1\\ 2 & 2\\ 3 & 4\\ 4 & 7\\ 5 & 12\\ 6 & 20\\ 7 & 33\\ \end{array} $$
So what I can determine is that between each step it looks like it adds the Fibonacci number for n onto the previous number. Does anyone have any thoughts on how I should determine a function for this? I do not understand these concepts very well unfortunately and it is scaring me.
