GATE Computer ScienceVery hardGATE CS (PYQ pattern)

int f(int k) { if (k <= 0) return 0; return g(k - 1) + 1; } int g(int k) { if (k <= 1) return 1; return f(k - 2) + f(k - 1); } During the evaluation of f(9), how many activation records (of f and g together, counting the first call) are created in all, and what is the maximum number alive at once?

  1. A. 32 created, 11 alive
  2. B. 29 created, 10 alive
  3. C. 36 created, 9 alive
  4. D. 32 created, 10 alive

Correct answer: D. 32 created, 10 alive

Running the mutual recursion gives 32 calls; the longest chain of simultaneously pending calls is 10.

More Compiler Design questions

Exams that ask this topic