Question-14
GATE-2023 (modified)
Python programming
recursion
Consider the following program:
Which one of the following options represents the activation tree corresponding to the main function?
-
main ├── f1 ├── f2 │ ├── f3 │ └── f2 │ ├── f3 │ └── f1 └── f3 -
main ├── f1 ├── f2 │ ├── f3 │ └── f1 └── f3 -
main ├── f1 ├── f2 │ ├── f3 │ └── f1 └── -
main ├── f1 ├── f2 │ ├── f3 │ ├── f2 │ └── f1 └── f3
NoteAnswer
-
main ├── f1 ├── f2 │ ├── f3 │ └── f2 │ ├── f3 │ └── f1 └── f3 -
main ├── f1 ├── f2 │ ├── f3 │ └── f1 └── f3 -
main ├── f1 ├── f2 │ ├── f3 │ └── f1 └── -
main ├── f1 ├── f2 │ ├── f3 │ ├── f2 │ └── f1 └── f3
NoteSolution
- main calls
f1,f2andf3. andf1andf3returns. - In
f2,f3is called andf2is called again withX=1as the condition goes to else part. - In the new
f2,f3is called andf1is called end the calls end there.