GATE Assistant

Past questions › Data Science and Artificial Intelligence › GATE 2026

GATE 2026 · DA · MCQ · 2 marks · Programming, Data Structures and Algorithms › Python Programming

GATE 2026 Data Science and Artificial Intelligence question: A recursive function in Python is given. code Now, consider the following function call:…

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

Show answer

Official answer: C

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion