GATE DA 2026 | Question 39
Programming, Data Structures and Algorithms › Recursion · MCQ · 2 marks · Answer: C
- Question 39Programming, Data Structures and Algorithmsmcq2 marksA recursive function in Python is given.
Now, consider the following function call:pythondef mystery(n): if n <= 0: return 1 else: return mystery(n-1) + mystery(n-2)mystery(4)Assume that a typical runtime stack is used to manage function calls. Each function call is pushed onto the stack and removed only after it finishes execution. Which of the following options denotes the total number of function calls (i.e., the total number of stack activations), including the initial call, to compute mystery(4)?- A.5
- B.9
- C.15✓
- D.17
Answer: C
Solution
Let be the number of calls made bymystery(n), counting itself. Then for , and for . - - - - - Answer: (C) 15. - A.
Attempt GATE DA 2026 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →