Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
hard Solved by 2 students

Bubble Sort Time Complexity

Mark
< Prev
Next >

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)

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|