GATE Computer ScienceVery hardGATE CS (PYQ pattern)

int A(int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } Each activation record needs 16 bytes. What is the maximum stack space occupied by activation records of A while evaluating A(2, 3), counting the outermost call as one record?

  1. A. 160 bytes
  2. B. 128 bytes
  3. C. 208 bytes
  4. D. 704 bytes

Correct answer: A. 160 bytes

Simulating the recursion, the deepest nesting of live calls is 10 (the whole run makes 44 calls and returns 9); 10 × 16 = 160 bytes. The total call count is not the stack size.

More Compiler Design questions

Exams that ask this topic