What is the time complexity of the bubble sort algorithm in the worst-case scenario?

  • O(log n)
  • O(n log n)
  • O(n)
  • O(n^2)
The worst-case time complexity of the bubble sort algorithm is O(n^2), where n represents the number of elements in the array. This means that the time taken to sort the array increases quadratically with the number of elements. Bubble sort repeatedly iterates through the array, comparing adjacent elements and swapping them if they are in the wrong order. Due to its nested loops, bubble sort has poor performance, especially for large datasets, making it inefficient for real-world applications.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *