GATE | GATE-CS-2005 | Question 82
Consider the following C-function:
Suppose we modify the above function foo() and store the values of foo (i), 0 < = i < n, as and when they are computed. With this modification, the time complexity for function foo() is significantly reduced. The space complexity of the modified function would be:
Explanation: Space complexity now is also O(n).
We would need an array of size O(n). The space required for recursive calls would be O(1) as the values would be taken from stored array rather than making function calls again and again.
Quiz of this Question