GATE Computer ScienceEasyGATE CS (PYQ pattern)

Consider t(n): if n ≤ 2 return 1; else return t(n−1) + t(n−2) + t(n−3). How many calls to t (including the initial call) are made when evaluating t(8)?

  1. A. 57
  2. B. 113
  3. C. 157
  4. D. 85

Correct answer: D. 85

Calls satisfy C(n) = 1 + C(n−1) + C(n−2) + C(n−3) with C(0) = C(1) = C(2) = 1: C(3) = 4, C(4) = 7, C(5) = 13, C(6) = 25, C(7) = 46, C(8) = 85. 57 is the value t(8) (the number of leaf calls); 113 = 2·t(8) − 1 wrongly applies the Fibonacci rule calls = 2·F − 1.

More Algorithms questions

Exams that ask this topic