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)?
- A. 57
- B. 113
- C. 157
- 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
- How many times is x++ executed? for (i = 2; i <= 100; i++) for (j = ii; j <= 100; j += i) x++;
- How many times is x++ executed? for (i = 1; i <= 1000; i = 2) for (j = i; j >= 1; j /= 3) x++; (integer division)
- Let f(n) = (log₂ n)^(log₂ n), g(n) = n^(log₂ log₂ n) and h(n) = (log₂ log₂ n)!. Which of the following is correct? I. f(n) = Θ(g(n)). II…
- Let f₁ = n^(1/log₂n), f₂ = (log₂ n)³, f₃ = (log₂ n)^(log₂ log₂ n), f₄ = 2^√(log₂ n), f₅ = n^0.001. Which lists them in increasing order of…
- In the median-of-medians selection algorithm the input is split into groups of g elements (g odd), giving the standard recurrence T(n) ≤…
- n keys, each an n-bit unsigned integer, are sorted by LSD radix sort that treats each key as digits of r = ⌊log₂ n⌋ bits (radix 2^r) and…