What is the worst-case behavior (number of comparisons) for bubble sort?
2019
What is the worst-case behavior (number of comparisons) for bubble sort?
Answer: D. O(n2) — Bubble sort compares adjacent elements repeatedly. In the worst case, it makes a quadratic number of comparisons, so the behavior is O(n^2).
- A.
O(1)
- B.
O(n log n)
- C.
O(n)
- D.
O(n2)
Attempted by 494 students.
Show answer & explanation
Correct answer: D
Bubble sort compares adjacent elements repeatedly. In the worst case, it makes a quadratic number of comparisons, so the behavior is O(n^2).
Loading lesson…