Machine-translated by Google. Questions are authored in English.
Top

Discussion

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

  • A.O(n)
  • B.O(n logn)
  • C.O(n^2)
  • D.O(log n)

Answer: A

The best-case time of bubble sort is O(n).

With the usual optimisation, bubble sort stops when a pass makes no swaps. If the array is already sorted, the first pass of n - 1 comparisons finds no swaps, so it finishes in linear time.

\(O(n^2)\) is its average and worst case, \(O(n \log n)\) belongs to efficient sorts such as merge sort, and O(log n) is binary search.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.