GATE Computer ScienceEasyGATE CS (PYQ pattern)

Same function f(n) = 1 for n ≤ 2, else f(n − 1) + f(n − 2) + f(n − 3). Each activation record takes 28 bytes. What is the maximum stack space used by activation records during the evaluation of f(9)?

  1. A. 224 bytes
  2. B. 252 bytes
  3. C. 196 bytes
  4. D. 4396 bytes

Correct answer: A. 224 bytes

The first argument decreases by 1 on the longest path: f(9), f(8), …, f(2) are live together, 8 records × 28 = 224 bytes.

More Compiler Design questions

Exams that ask this topic