Q39Section DA (Data Science and Artificial Intelligence (Q11–Q65))39 of 65
Total function calls made computing a Fibonacci-like recursive function
A recursive function in Python is given.
def mystery(n):
if n <= 0:
return 1
else:
return mystery(n-1) + mystery(n-2)
Now, consider the following function call:
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)?
Pick an option to check your answer. In a mock test a wrong answer here costs 2/3 mark.