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)?
- A. 6
- B. 7
- C. 13
- 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
- How many ordered ways are there to write 10 as a sum of parts equal to 1, 3 or 4, where the order of the parts matters?
- int arr[10]; What is sizeof(int[10]) / sizeof(int)?
- What does printf("%d", 10 / 3 3 == 10) print?
- int x = 3; printf("%d", x << 2 | x >> 1); What is printed?
- unsigned char c = 0x80; c >>= 1; printf("%d", c); What is printed?
- uint64t big = (uint64t)0xFFFFFFFF 2; What is big?