Which of the following best describes the bubble sort algorithm?

  • Compares adjacent elements
  • Divides array into smaller arrays
  • Picks a random element for sorting
  • Places smallest element first
Bubble sort compares adjacent elements in the array and swaps them if they are in the wrong order. This process continues until the entire array is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the array during each iteration. This sorting method is simple to implement but is inefficient for large datasets, as it has a time complexity of O(n^2) in the worst case, where n is the number of elements in the array.
Add your answer
Loading...

Leave a comment

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