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 no swaps are needed, which indicates that the list is sorted.
It is named because elements tend to move up into the correct order like bubbles rising to the surface.
Best | Average | Worst | Space (Memory) | Stable | Advantage |
---|---|---|---|---|---|
O(n) | O(n2) | O(n2) | O(1) | Yes | Simplicity |