Bubble Sort🐱‍👤

Tehleel Mir
Mar 9, 2022

Bubble sort is a sorting algorithm used to sort an array/list

Time Complexity
In the worst case, the time complexity of a bubble sort is O(n²) and in the best case, it's O(n).

Explanation
The bubble sort is almost the same as the selection sort, but in the selection sort, the time complexity remains the same in all the cases (best, average, and worst). While as in bubble sort in the best cases i.e. when the array/list is already sorted time complexity will be O(n) because of the flag which we use in bubble sort. That flag helps us to check whether the list is already sorted or not. And in the case of selection sort no matter whether the list is sorted or not it will still run the same number of operations on the list.

Code

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response