for (int front = 1; front < intArray.length; front++)
{
for (int i = 0; i < intArray.length - front; i++)
{
if (intArray[i] > intArray[i + 1])
{
int temp = intArray[i];
intArray[i] = intArray[i + 1];
intArray[i + 1] = temp;
}
}
}
The inner loop is iterating: n + (n-1) + (n-2) + (n-3) + ... + 1 times.
The outer loop is iterating: n times.
So you get n * (the sum of the numbers 1 to n)
Isn't that n * ( n*(n+1)/2 ) = n * ( (n^2) + n/2 )
Which would be (n^3) + (n^2)/2 = O(n^3) ?
I am positive I am doing this wrong. Why isn't O(n^3)?