Each thread had a separate problem. Maybe they should have been combined.
T(n+1) = T(n) + floor(sqrt(n+1))
T(1) = 1.
(I assumed that ⌊ ⌋ meant the integer floor of the sqrt).
Note that floor(sqrt(1->3)) = 1, floor(sqrt(4 -> 8)) = 2, floor(sqrt(9->15)) = 3, ... .
T(m^2) = m + 1*0 + 3*1 + 5*2 + 7*3 + ... + (2m-1)(m-1)
T(m^2) = m + sum i=1 to m: (2i - 1)(i - 1)
Which is a cubic equation of the form (I'll let you solve this one):
T(m^2) = a m^3 + b m^2 + c m
I don't know if there's a more generic method to solve this.
- - -
T(n) = 2 T(n/2) + 2
T(1)=2
Code:
n=2 2
2 2n=4 2
2 2
2 2 2 2 n=8 2
2 2
2 2 2 2
2 2 2 2 2 2 2 2
sum i=1 to log2(2n) : 2^i
2 T(n) - T(n) = T(n):
2 T(n) = 4 + 8 + 16 + ... + 2^(log2(2n)) + 2^(log2(4n))
T(n) = 2 + 4 + 8 + 16 + ... + 2^(log2(2n))
----------------------------------------
T(n) = -2 + 2^(log2(4n))
T(n) = -2 + 4n
T(n) = 4n - 2
- - -
For the summation series in the first post above, I used power series method, subracting 1 x series from 2 x series:
Code:
2(T(n)) = (2)(n ) + (2^2)(n-1) + (2^3)(n-2) + ... + 2^(n-1)(2) + 2^(n)
T(n) = (1)n + (2)(n-1) + (2^2)(n-2) + (2^3)(n-3) + ... + 2^(n-1)(1)
----------------------------------------------------------------------------
T(n) = -n + (2) + (2^2) + (2^3) + 2^(n-1) + 2^(n)
2(T(n)+n) = (2^2) + (2^3) + ... + 2^(n-1) + 2^(n) + 2^(n+1)
T(n)+n = (2) + (2^2) + (2^3) + ... + 2^(n-1) + 2^(n)
-----------------------------------------------------------------
T(n)+n = -2 + 2^(n+1)
T(n) = 2^(n+1) - n - 2