int f(int n)
{
if (n <= 1)
{
return 1;
}
return f(n - 1) + f(n - 1);
}
I know that the time complexity is O(2^n) and I understand why.
But I don't understand why the space complexity is O(n).
I was told that it's because at any given time there are only n nodes, but it doesn't make sense to me.
Memory(n) = 1 + max(Memory(n-1), Memory(n-1))– Raymond Chen 4 hours ago