function T(int n) { int n1 = T((n-1)/4) int n2 = T((n+1)/4)
int sum = 0 for i = 1 to n { for j = 1 to n { sum+=n1*i + n2*j } } return sum }
T(n) = ?
The orange line is T(n) = O(n2), The blue things are the origin data.
It should be O(n2)
If you have interest, c likely equals to 346252 for cn2.
Why:
(1) int n1 = T((n-1)/4) costs O(logn) and make n1 = 1
(2) so as n2
(3) two recursive calls cost O(n2)
Therefore, O(n2) in total.
Image seems crash. here is the URL: https://github.com/wfgydbu/swap/blob/master/tt1.jpg
Here is my try, please let me know if it's correct or not.
T(n)= T(n-1) + n2
Since the value of a= 1, then T(n) = O (n k+1)
This means that T(n) = O(n3)