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)?
- A. 27
- B. 18
- C. 31
- D. 21
Correct answer: A. 27
A(2,2) = 7; counting every invocation in the expansion gives 27 calls.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Thirteen people numbered 1 to 13 stand in a circle (circular linked list). Starting the count at person 1 (who counts as 1), every 4th…
- A disjoint-set forest over elements 1..8 starts with each element as its own root. It uses union by rank (on equal ranks, the root of the…
- On a machine where char needs 1-byte, short 2-byte and int 4-byte alignment (each member at the next offset divisible by its own size, and…
- A directed acyclic graph on vertices 1–6 has edges 1→3, 2→3, 3→4, 2→5, 4→6, 5→6 and 1→5. How many distinct topological orderings does it…
- A complete binary tree with 100 nodes (levels filled left to right, array positions 1 to 100) is given. Let X be the number of leaves and…
- int G(int n) { if (n < 3) return 1; return G(n-1) + G(n-2) + G(n-3); } Including the initial call, how many calls to G are made in total…