What is the worst-case time complexity of bubble sort?
A
O(n)
B
O(n log n)
C
O(n^2)
D
O(log n)
Correct Answer: Option C — O(n^2)
Explanation:
Bubble sort has a worst-case time complexity of O(n squared) because it may need to make multiple passes, comparing and swapping adjacent el...
Bubble sort has a worst-case time complexity of O(n squared) because it may need to make multiple passes, comparing and swapping adjacent elements repeatedly.