GATE CSE 2023 Q36: Activation tree of main for recursive calls to f2
- Compiler Design
- 2 marks
- MCQ
- −2/3 if wrong
Question
Consider the following program, and the four activation trees (A)–(D) shown after it:
int main()
{
f1();
f2(2);
f3();
return(0);
}
int f1()
{
return(1);
}
int f2(int X)
{
f3();
if (X==1)
return f1();
else
return (X*f2(X-1));
}
int f3()
{
return(5);
}
Which one of the following options represents the activation tree corresponding to the main function?
Try it: multiple choice: exactly one correct option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation
Answer: A (official GATE 2023 final answer key)
Concept used: An activation tree has one node per call; the children of a node are the calls it makes, in order.
First step: Trace f2(2): it calls f3, then f2(1); f2(1) calls f3 and then f1.
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2023 CS question paper and final answer key, organised by IIT Kanpur. Question paper · Answer key
More Compiler Design PYQs
- 2026 Session 1 · Q27Classify errors in three C string declarations
- 2026 Session 1 · Q28True statements about LL(1) parsing
- 2026 Session 1 · Q42Redundant (common) subexpressions in blocks B4 and B5 of a CFG
- 2026 Session 1 · Q53Compare two SDDs for type declarations
- 2026 Session 2 · Q35Count tokens produced by a lexer for a given string
- 2026 Session 2 · Q41Shift-reduce conflicts in the LR(0) table of a grammar