public int fib(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
return fib(n-1) + fib(n-2);
}
I am confused why the space complexity of the above code is O(n).
Now, I know the depth of recursion is n
, that is, the height of the tree.
There are no temporary variables or final result variables created. Is the space complexity here computed from the function call stack?