A recursive function in Python is given. def mystery(n): if n <= 0: return 1…

PYQ GATE 2026

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)?

  1. A.

    5

  2. B.

    9

  3. C.

    15

  4. D.

    17

Attempted by 68 students.

Sign up free to check your answer

Sign up free

Explore the full course: Data Structures

Loading lesson…