Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted.
source: Wikipedia
In this implementation the bound
variable is used to improve the efficiency. Specifies the location of the last swap, this means that all items after the last swap are already sorted and you don't have to compare them again.
Algorithm | Best | Average | Worst | Space |
---|---|---|---|---|
Bubble sort | Ω(n) | Θ(n2) | O(n2) | O(1) |