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)); } Each activation record needs 16 bytes. What is the maximum stack space occupied by activation records of A while evaluating A(2, 3), counting the outermost call as one record?
- A. 160 bytes
- B. 128 bytes
- C. 208 bytes
- D. 704 bytes
Correct answer: A. 160 bytes
Simulating the recursion, the deepest nesting of live calls is 10 (the whole run makes 44 calls and returns 9); 10 × 16 = 160 bytes. The total call count is not the stack size.
More Compiler Design questions
- For S → id | id [ E ] | id ( E ); E → id (augmented with S′ → S), how many states do the LR(0) and the canonical LR(1) automata have?
- The grammar S → A B; A → a A | a; B → a B | a is ambiguous. How many distinct parse trees does the string "a a a a a a" have?
- For the declaration grammar D → T L; T → int | float; L → L , id | id (augmented with D′ → D), how many states does the LR(0) automaton…
- Build the SLR(1) table of S → A a | b A c | d c | b d a; A → d (augmented). Which option describes all of its conflicts?
- Compute FIRST of every non-terminal of S → A B | B C; A → a A | ε; B → b B | ε; C → c C | c, treating ε as a member of FIRST when the…
- With int i = 2 and the array A = [0, 3, 5, 7, 9, 11, 13] (indices from 0), the call f(A[i], i) is made to void f(p, q) { i = i + 1; p = p…