What is the best case time complexity for bubble sort?

What is the best case time complexity for bubble sort?

a) O(n log n)
b) O(n)
c) O(n^2)
d) O(1)

Answer:

b) O(n)

Explanation:

The best case time complexity for bubble sort is O(n). This occurs when the input array is already sorted, so no swaps are needed, and the algorithm only makes one pass through the array to verify that no further sorting is required.

In contrast, the average and worst-case time complexities for bubble sort are O(n^2) because, in those cases, the algorithm may need to perform multiple passes and swaps to sort the elements.

Bubble sort is simple to implement but inefficient for large datasets, so it is mainly used for educational purposes or when the dataset is small and almost sorted.

Reference:

DSA (Data Structures and Algorithms) MCQ Questions and Answers

Scroll to Top