The question "what does the stack frame look like?" doesn't have a single answer. The answer depends on at what point we look at the stack frame.
The sequence of calls looks like this:
f(4)
f(2)
f(0)
f(0)
f(2)
f(0)
f(0)
If we set a breakpoint at the return for when n <= 1
and called f(4)
, we'd hit the breakpoint inside the first call to f(0)
in the sequence above. The stack frame would look something like this (assuming stack grows from top of allocated frame downward, and we're dumping memory from the SP to sequentially higher memory, both of which are typical):
0
PC of f(0) call
2
PC of f(2) call
4
PC of f(4) call
For this function, bigO is the same as big theta, and I believe Mike P got it right: 2^(n/2). To see why, try writing the call sequence for f(6)
and f(8)
and hopefully you'll see the pattern: every time you add two to the parameter, the number of calls doubles.
For a more complete answer, see Computational complexity of Fibonacci Sequence . This is not the Fibonacci series, but the algorithm has the same complexity.