Gradient LabSign up free

Home / GATE DA / 2026 / Q.39

GATE DA 2026, Q.39: Stack activations for mystery(4)

ProgrammingRecursion call count2 marksMCQFree

The question

For the code below, how many stack activations (including the initial call) does mystery(4) create?

def mystery(n):
    if n <= 0:
        return 1
    else:
        return mystery(n-1) + mystery(n-2)

mystery(4)

Watch it solved

Solve it step by step

  1. Count rule. calls(n) = 1 + calls(n − 1) + calls(n − 2) for n > 0, and calls(n) = 1 for n ≤ 0.
  2. Base. calls(0) = calls(−1) = 1.
  3. Build up. calls(1) = 3, calls(2) = 5, calls(3) = 9.
  4. Answer. calls(4) = 1 + 9 + 5 = 15.

Answer: (C) 15

Official IIT Guwahati answer key: C.

Common mistake. Stopping the recursion at n = 1; the base case is n ≤ 0, so mystery(1) still makes two more calls.

Remember. Count calls with the same recurrence as the function, plus 1 for the call itself.

Want every question solved? The past-paper pack has all 195 questions from 2024, 2025 and 2026 for ₹499. The cheat sheet pack has 23 printable sheets for ₹399.

See the past-paper pack See the cheat sheets

Source: official GATE DA 2026 question paper and answer key (IIT Guwahati). The question is lightly reworded; every number and option is kept.