Why is bubble sort O(n^2)?
int currentMinIndex = 0; for (int front = 0; front < intArray.length; front++) { currentMinIndex = front; for (int i = front; i < intArray.length; i++) { if (intArray[i] < intArray[currentMinIndex]) { currentMinIndex = i; } } int tmp = intArray[front]; intArray[front] = intArray[currentMinIndex]; intArray[currentMinIndex] = tmp; } 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