algo·visual

Bubble Sort

Sorting
avgO(n²)worstO(n²)spaceO(1)
6
10
97
71
54
43
49
27
57
74
29
19
77
54
23
39
32
55
33
97
28
88
23
18

Start with 24 unsorted values

1 / 462
Size24
Distribution
Custom values2 to 150 whole numbers, each 1 to 999

seed 7

How it works

Repeatedly steps through the list, compares adjacent pairs and swaps them if they are out of order. Each pass bubbles the largest remaining element to the end, and a pass with no swaps means the list is sorted.

Complexity

Best
O(n)
Average
O(n²)
Worst
O(n²)
Space
O(1)
Stable
Yes
In place
Yes

Search algorithms

Jump to any algorithm or page