According to the definitions on wikipedia (http://en.wikipedia.org/wiki/Big_O_notation#Family_of_Bachmann.E2.80.93Landau_notations)
Big Omicron O - function is bounded above (by up to constant factor) asymptotically
Your analysis of O(n^2) is correct (though your anyalysis of swap is wrong)
Big Omega Ω - function is bounded below asymptotically
Your analysis of Ω(n^2) is correct (though your anyalysis of swap is wrong)
Big Theta Θ - is bounded both above and below by g asymptotically
As the Big Omnicron and Big Omega are the same, the big Theta is the same as those two: Θ(n^2)
As for detailed analysis of each part:
The outside-loop does run n-1
, and there's one inner-loop and swap per iteration of that. Ergo, there is n-1
swaps as well.
The inner-loop-body runs n-m times for each m, which is where the math gets complicated. The T[k] < T[j]
gets executed ((n-1)-1)(n-2)/2 = (n^2)/2+2-2
times (I think).
The j = k
is harder still, because now probability gets involved. I think it's the sum of lg(m)
where m
is the numbers 1 to n-1
. After much math, I think that's lg(n!)/0.60206
, and no, I have no idea where that constant came from or what it means.
You should know, your code is a Selection Sort, and the wikipedia page on selection sorts backs up my thoughts.