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)); } How many calls to A (including the first) does evaluating A(2, 1) make, and what does A(2, 3) return?

  1. A. 14 calls, value 11
  2. B. 18 calls, value 9
  3. C. 11 calls, value 7
  4. D. 14 calls, value 9

Correct answer: D. 14 calls, value 9

A(1, n) = n + 2 and A(2, n) = 2n + 3. So A(2,3) = 9. Counting every call in the recursion tree for A(2,1) gives 14.

More Programming and Data Structures (GATE) questions

Exams that ask this topic