Bubble sort

Time complexity: O(n²).

Result

Examples

How it works

Bubble sort walks the list swapping neighbours that are out of order, so large values bubble to the end. It stops early when a pass makes no swaps.

When to use it

Teaching. It is almost always slower than insertion sort.

Other algorithms