GATE Computer ScienceVery hardGATE CS (PYQ pattern)
int f(int k) { if (k <= 0) return 0; return g(k - 1) + 1; } int g(int k) { if (k <= 1) return 1; return f(k - 2) + f(k - 1); } During the evaluation of f(9), how many activation records (of f and g together, counting the first call) are created in all, and what is the maximum number alive at once?
- A. 32 created, 11 alive
- B. 29 created, 10 alive
- C. 36 created, 9 alive
- D. 32 created, 10 alive
Correct answer: D. 32 created, 10 alive
Running the mutual recursion gives 32 calls; the longest chain of simultaneously pending calls is 10.
More Compiler Design questions
- After applying left factoring repeatedly (each time extracting the longest common prefix of alternatives that share a first symbol…
- A DAG is built for r = (p − q) (p − q) + (q − p) (p − q) − (p − q), with commutative and − not commutative. How many interior (operator)…
- For the grammar S → C C; C → c C | d (augmented with S′), the canonical LR(1) automaton is built and then the states with identical LR(0)…
- Using the backpatching scheme (each relation gives 'if r goto ' then 'goto ', no fall-through optimisation, numbering from 100), the code…
- For the nested-loop code 1: s = 0; 2: i = 0; 3: L1: if i >= n goto L5; 4: j = 0; 5: L2: if j >= i goto L4; 6: s = s + j; 7: j = j + 1; 8…
- For the grammar E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id, what is FOLLOW(T)?