views:

79

answers:

2

Can anyone help me finding the time complexity of

T(n)=1 if n<=0 T(n)=T(n-1)+T(n-2)+n

A: 

According to OEIS, the closed formula for this function is , which means that the asymptotic complexity of this functions is alt text.

svick
+2  A: 

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.

Moron
I agree with the conclusion, but I think the proof is wrong: the “i.e.” part is incorrect.
svick
@Svick: It is basic arithmetic! I didn't say it was _the_ fibonacci sequence. The terms are different.
Moron
@Moron: Yeah, it basic arithmetic, but `(n+1) != (n-1)` and you can't just ignore that.
svick
@svick: You are right! I have edited the answer. Thanks for pointing the error. I do need new eyes! To be fair (to myself I suppose :-)), those constant terms can be ignored when talking about BigOh. i.e F(n) = F(n-1) + F(n-2) + K has same asymptotics as fibonacci.
Moron
@svick: btw, sorry about that. I should have been more careful, especially after when you were kind enough to comment.
Moron
@Moron: No problem.
svick