GATE Computer ScienceModerateGATE CSE · TCS

int f(int n) { if (n < 2) return 1; return f(n - 1) + f(n - 2); } Including the initial call, how many times is f invoked while evaluating f(6)?

  1. A. 15
  2. B. 27
  3. C. 13
  4. D. 25

Correct answer: D. 25

Calls C(n) = 1 + C(n−1) + C(n−2) with C(0)=C(1)=1 give 1,1,3,5,9,15,25; so C(6) = 25.

More Programming and Data Structures (GATE) questions

Exams that ask this topic