GATE Computer ScienceEasyGATE CS (PYQ pattern)

int f(int n) { if (n == 0) return 1; return f(n - 1) + f(n - 1); } How many calls to f (including the first) does f(10) make?

  1. A. 1024
  2. B. 2047
  3. C. 1023
  4. D. 11

Correct answer: B. 2047

The call tree is a complete binary tree with levels n = 10, 9, ..., 0, so 2^11 - 1 = 2047 calls (not 2^10).

More Programming and Data Structures (GATE) questions

Exams that ask this topic