I am reading Cracking the Code Interview 6th Edition and have a question about something on page 45.
There is an example algorithm like this:
int f(int n){
if (n <= 1)
return 1;
return f(n - 1) + f(n - 1);
}
For the algorithm it gives the following comment:
The space complexity of this algorithm will be O(N). Although we have O(2^N) nodes in the tree total, only O(N) exist at any given time. Therefore, we would only need to have O(N) memory available.
I don't really understand why only O(N) exist at any given time. Shouldn't all of them be in the call stack? Can somebody explain this?