What is the best-case time complexity for the Bubble Sort algorithm ?

2025

What is the best-case time complexity for the Bubble Sort algorithm ?

  1. A.

    O(n)

  2. B.

    O(n log n)

  3. C.

    O(n2)

  4. D.

    O(log n)

Attempted by 176 students.

Show answer & explanation

Correct answer: A

Bubble Sort works by repeatedly swapping adjacent elements if they are in the wrong order. In the best-case scenario, the input array is already sorted. A standard optimized Bubble Sort implementation includes a flag to detect if any swaps occurred during a pass. If no swaps are made in a complete pass through the array, the algorithm terminates immediately because it recognizes that the list is sorted. This means the algorithm only performs a single pass through all n elements to verify their order, resulting in linear time complexity. Therefore, the best-case time complexity is O(n). Other options like O(n log n) or O(n2) represent average and worst-case scenarios respectively, while O(log n) is not achievable for comparison-based sorting algorithms that must inspect every element.

Explore the full course: Tpsc Assistant Technical Officer