Consider the following program:
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?
Tap to open full sizeFigure description
Four candidate activation (call) trees, each rooted at a node labeled 'main': (A) main has three children f1, f2, f3 (left to right). Below the f2 child, a next level shows two nodes f3, f2. Below that second f2 node, a next level shows two nodes f3, f1. (B) main has three children f1, f2, f3. Below them (drawn as a single next level) two nodes f3, f1 — i.e., only one further level of nesting shown, attached under f2. (C) main has a single child f1. Below f1 a single child f2. Below f2 two children f3, f1. (D) main has three children f1, f2, f3. Below that, one flat row of three nodes f3, f2, f1, all shown as children of the f2 node (not further nested).
- (A)
Figure — main → (f1, f2, f3); the f2 node → (f3, f2); that inner f2 node → (f3, f1)
- (B)
Figure — main → (f1, f2, f3); below → (f3, f1) only (missing one level of recursive nesting)
- (C)
Figure — main → (f1); f1 → (f2); f2 → (f3, f1)
- (D)
Figure — main → (f1, f2, f3); f2 → (f3, f2, f1) all as one flat row of children