GATE DA 2026 Q39: Number of calls made by a Fibonacci-like recursion
- Programming, Data Structures and Algorithms
- 2 marks
- MCQ
- −2/3 if wrong
Question
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)?
Try it: multiple choice: exactly one correct option
Show answer and explanation
Answer: C (official GATE 2026 final answer key)
Concept used: Count calls with a recurrence: for , and for .
First step: , , , , then .
Full step-by-step solution
Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.
Share this question
Source: official GATE 2026 DA question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key
More Programming, Data Structures and Algorithms PYQs
- 2026 · Q15Expected-time recurrence for randomised-input quicksort
- 2026 · Q16Python mutable default argument output
- 2026 · Q25Binary tree from preorder and inorder traversals
- 2026 · Q31Worst-case comparisons in binary search of 1000 elements
- 2026 · Q40Reachability in a graph and its reverse
- 2026 · Q49Comparisons by bubble sort and insertion sort on a nearly sorted array