GATE Computer ScienceHardGATE CSE

int G(int n) { if (n < 3) return 1; return G(n-1) + G(n-2) + G(n-3); } Including the initial call, how many calls to G are made in total when G(12) is evaluated (no memoisation)?

  1. A. 1019
  2. B. 979
  3. C. 941
  4. D. 1469

Correct answer: B. 979

Calls satisfy N(n) = 1 + N(n−1) + N(n−2) + N(n−3) with N(0..2) = 1; evaluating up to n = 12 gives 979.

More Programming and Data Structures (GATE) questions

Exams that ask this topic