Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2

Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(11) and count every invocation of f, including the first call. How many calls to f are made in total?

  1. A. 81
  2. B. 41
  3. C. 110
  4. D. 55

Correct answer: A. 81

Each call spawns the recursive branches listed, so f(11) makes 81 invocations in total. The returned value 41 and a smaller argument's call count are different quantities.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic