Reqflow
Sorting·Beginner

Bubble Sort

Time O(n²)Space O(1)
·

Bubble sort repeatedly steps through the array, comparing each pair of adjacent elements and swapping them if they are in the wrong order. After each full pass the largest remaining value has bubbled to its correct spot at the end. It is slow on large inputs, but it is the clearest way to see what sorting actually does.

Example: Sort 6 numbers in ascending order.

When to use this

See also

← All algorithms