Asymptotic Analysis & Recurrences



Answer & solution
Answer: B (no official key was published)
Every activation stores only a constant number of locals, but calls are nested. A path foo(n)→foo(n−1)→…→foo(0) reaches n+1 simultaneous activations. The loop calls execute sequentially, so the exponentially many calls are not all live at once. Maximum stack space is Θ(n), option B.
Count simultaneously live activations, not total recursive calls. During its last recursive branch, foo(n) may be suspended while foo(n−1), foo(n−2),…, foo(0) are active, giving linear depth. Each frame contains only a constant number of scalar locals. Separate loop iterations return before the next call, so their storage is reused. This distinguishes linear stack space from exponential running time. Larger Big-O choices are also loose bounds; the intended answer describes the tight growth.