Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional

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

  1. A. 134
  2. B. 34
  3. C. 109
  4. D. 67

Correct answer: C. 109

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic