Bubble Sort Time Complexity
Which of the following represents the time complexity of the bubbleSort method shown below?
public static void bubbleSort(int[] arr) {
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
A
O(1)
B
O(log n)
C
O(n^2)
D
O(n)
Question Leaderboard
Not enough data yet to show leaderboard.
