Bubble Sort🐱👤
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.