I was reading this question, and this comment in precise captured my attention Stackoverflow
The comment says that in order to achieve O(n log n) we would need the outer loop to be: for(int i = 0; i < n; i++)
and the nested loop to be: for(int j = n; j > 0; j/=2)
, which makes the nested loop domain: from n to n/2.
I understand that the to find the time complexity, we take into consideration the input size, and the number of steps it takes to run the computation, but it seems to me that it depends solely on the step-through portion, and how to minimize the number of steps to get from 0 to n (or vice versa). Is my understanding correct ?
If this is true, then changing the nested loop to for(int j = n/2; j > 0; j--)
or for(int j = n/4; j > 0; j--)
( which would make the the domain between 0 and n/2 or n/4 respectively) would still keep the algorithm complexity time n*(n/2) or n*(n/4) = n^2
I appreciate any explanation.