ProgrammingHardGATE CS · Campus placements

Ackermann-style recursion: A(0,n) = n + 1 and A(m,0) = A(m-1,1), with A(m,n) = A(m-1, A(m,n-1)). What is A(1,5)?

  1. A. 6
  2. B. 7
  3. C. 13
  4. D. 10

Correct answer: B. 7

Unrolling gives A(1,n) = A(0, A(1,n-1)) = A(1,n-1) + 1 with A(1,0) = A(0,1) = 2, so A(1,n) = n + 2 and A(1,5) = 7. 6 uses the m = 0 rule n + 1, 13 uses A(2,n) = 2n + 3, and 10 guesses doubling.

More C Programming questions

Exams that ask this topic