GATE Computer ScienceVery hardGATE CSE · ISRO

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)); } How many times is A invoked in total (counting the first call) when evaluating A(2, 2)?

  1. A. 27
  2. B. 18
  3. C. 31
  4. D. 21

Correct answer: A. 27

A(2,2) = 7; counting every invocation in the expansion gives 27 calls.

More Programming and Data Structures (GATE) questions

Exams that ask this topic