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.

[links added]

(“Bubble Sort” 2022)

Bubble sort is stable.

Algorithm

while list is not sorted do
  for i in range(len(list) - 1) do
    if list[i] > list[i+1] do
      swap(i, i+1)

Implementation

Complexity

Worst-caseBest-case
Time\(O(n^2)\)\(O(n)\)
Space\(O(n)\)\(O(n)\)

Bibliography