![]() |
Python
1.0
|
Sorting lists. More...
Functions | |
def | bubble_sort (v) |
Sorts a list using bubble sort. More... | |
def | main () |
Sorting lists.
Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, most of the other sorting algorithms are more efficient for large lists.
Bubble sort has worst-case and average complexity both \(O(n^{2})\), where n is the number of items being sorted. Performance of bubble sort over an already-sorted list (best-case) is \(O(n)\).
def _04e_bubble.bubble_sort | ( | v | ) |
def _04e_bubble.main | ( | ) |
References bubble_sort().