johnchen902 is correct:
alg(n)=Ξ(Ο^n) where Ο = Golden ratio = (1 + sqrt(5)) / 2
but his argument waves his hand a little, so let him become strict. His initial argument was incomplete, so I added mine, but now he has completed the discussion .
loop body = Ξ(3n+1)
Denote the cost of the loop body for argument n with g(n) . Then g(n) β Ξ(n) , since Ξ(n) = Ξ(3n+1) .
Next, let T(n) be the total cost alg(n) for n >= 0 . Then for n >= 2 we have recurrence
T(n) = T(n-1) + T(n-2) + g(n)
For n >= 3 we can insert the repetition applied to T(n-1) into the fact that
T(n) = 2*T(n-2) + T(n-3) + g(n) + g(n-1)
and for n > 3 , we can continue by applying repetition to T(n-2) . For sufficiently large n , therefore, we have
T(n) = 3*T(n-3) + 2*T(n-4) + g(n) + g(n-1) + 2*g(n-2) = 5*T(n-4) + 3*T(n-5) + g(n) + g(n-1) + 2*g(n-2) + 3*g(n-3) ... k-1 = F(k)*T(n+1-k) + F(k-1)*T(nk) + β F(j)*g(n+1-j) j=1 n-1 = F(n)*T(1) + F(n-1)*T(0) + β F(j)*g(n+1-j) j=1
with Fibonacci numbers F(n) [ F(0) = 0, F(1) = F(2) = 1 ].
T(0) and T(1) are some constants, therefore the first part is obviously Ξ(F(n)) . It remains to investigate the amount.
Since g(n) β Ξ(n) , we only need to investigate
n-1 A(n) = β F(j)*(n+1-j) j=1
Now,
n-1 A(n+1) - A(n) = β F(j) + (((n+1)+1) - ((n+1)-1))*F((n+1)-1) j=1 n-1 = β F(j) + 2*F(n) j=1 = F(n+1) - 1 + 2*F(n) = F(n+2) + F(n) - 1
Summarizing this, starting with A(2) = 2 = F(5) + F(3) - 5 , we obtain
A(n) = F(n+3) + F(n+1) - (n+3)
and therefore, for
c*n <= g(n) <= d*n
assessment
F(n)*T(1) + F(n-1)*T(0) + c*A(n) <= T(n) <= F(n)*T(1) + F(n-1)*T(0) + d*A(n)
for n >= 2 . Since F(n+1) <= A(n) < F(n+4) , all terms depending on n on the left and right sides of the inequality, Ξ(Ο^n) , qed