(https://i.sstatic.net/oTCBO87A.png) I have to calculate the complexity of this algorithm using the substitution method but I don't understand how to do it.
I'm guessing that T(n)=O(n^2)
. So I tried to prove it.
T(n)=O(n^2)
means that exists some c such as T(n)<=cn^2
for all n>=n0
.
I assume that this is true for all m<n
.
I take m=n/2<n
so I assume that T(n/2)<=c(n/2)^2
.
Now I try to substitute.
4T(n/2) + kn <= 4c(n/2)^2 + kn = cn^2 + kn
cn^2+kn
should be <= cn^2
but this is only true for k<0. What am I doing wrong? Can k be less than 0? Am I doing something wrong in the calculation or my guess is wrong?
[assumed this true] for all m<n
here you neglect the condition does not need to hold up to $n_0$. $\endgroup$