This is a rather complex function. Lets move from bottom up and maybe we can see something.
T(0) = 1
T(1) = 2 * (2 + T(0)) = 2 * (2 + 1) = 2 * 3 = 6
T(2) = 3 * (3 + T(1)) = 3 * (3 + 6) = 2 * 9 = 27
T(3) = 4 * (4 + T(2)) = 4 * (4 + 27) = 4 * 31 = 124
If we expand it differently
T(1) = 2 * (2 + T(0))
T(2) = 3 * (3 + 2 * (2 + T(0)))
T(3) = 4 * (4 + T(2)) = 4 * (4 + 3 * (3 + 2 * (2 + T(0))))
...
T(n) = (n+1) * (n+1 + T(n)) = (n+1) * (n+1 + n * (n + T(n -1))) =
(n+1) * (n+1 + n * (n + (n-1) * ((n-1) + T(n-2))))
Now if we open parenthises of T(n)
T(n) = (n+1)^2 + (n+1)n*(n + T(n-1)) = (n+1)^2 + (n+1)n^2 + (n+1)n(n-1)*((n-1) + T(n-1)) = ...
= (n+1)^2 + (n+1)n^2 + ... + (n+1)n(n-1)...2^2 + (n+1)! = Sum[iProduct[j,{j,i,n}],{i,2,n}] + (n+1)!
(I used wolfram alpha for the sum thing, i hope tis correct)
What can we see from the final sum is that the largest member of the sum is (n+1)!
Everything else will be smaller, so we can disregard those. Also the +1
is pointless so we can also drop that. End result is that your recursive function is o(n!)
.
If anyone asks why n+1
, it because the loop condition is i<=n
not i < n
.
Also i havent done this type of analysis for quite some years now, i hope i didnt make any major mistakes.