Data Structures & AlgorithmsVery hardGATE CS · competitive programming

Naive recursion fib(n) = fib(n−1) + fib(n−2), with base cases n < 2, makes calls to itself. How many calls in total does fib(10) make, counting the first call?

  1. A. 176
  2. B. 177
  3. C. 89
  4. D. 55

Correct answer: B. 177

With C(0) = C(1) = 1 and C(n) = 1 + C(n−1) + C(n−2), C(n) = 2·F(n+1) − 1 = 2·89 − 1 = 177. Forgetting the root call gives 176.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic