Dynamic Programming


Answer & solution
Answer: B (no official key was published)
Caching foo(i) for 0≤i<n requires n scalar values, hence Θ(n) space. Any recursive call stack is also at most O(n), so the total remains Θ(n), option B. Memoization reduces recomputation but does not require storing all call-tree nodes. This counts machine words, as in the question’s double-valued implementation.
Memoization allocates one result per argument value, a linear-size table, rather than one result per recursive-call occurrence. A recursive implementation can still have a linear stack, but adding two linear requirements remains linear. The table itself gives a linear lower bound in the stated storage scheme. Count constant-size machine words as specified by the double implementation; arbitrary-precision value bit lengths would be a different model.