Can anyone help me finding the time complexity of
T(n)=1 if n<=0 T(n)=T(n-1)+T(n-2)+n
Can anyone help me finding the time complexity of
T(n)=1 if n<=0 T(n)=T(n-1)+T(n-2)+n
Consider
F(n) = T(n) + n + 3.
This gives us
F(n) - (n+3) = F(n-1) - (n-1+3) + F(n-2) - (n-2+3) + n
i.e
F(n) - 3 = F(n-1) - 2 + F(n-2) - 1
i.e
F(n) = F(n-1) + F(n-2)
which is a Fibonacci like sequence!
It is well known that for fibonacci like sequences, F(n) = Theta(phi^n) where phi is the golden ratio.
(n+1) != (n-1) and you can't just ignore that.According to OEIS, the closed formula for this function is
, which means that the asymptotic complexity of this functions is
.