Bubble Sort
Random Array
Visualization Speed
Array Size
Comparisons: 0
Swaps: 0
Time: 0 milliseconds
Color CodeMeaning
Values to be swap
Values to be swap
Max size of the array that has to be checked
ith iteration0
jth iteration0
Jth element of an array0
(J+1)th element of an array0
22
20
28
24
31
11
33
17
35
38
22
32
30
12
28
32
35
18
12
10
17
19
12
38
37
37
35
28
39
29
20
19
33
32
10
32
18
33
24
36
See all Intermediate Stages

Description

Bubble Sort is an iterative sorting algorithm that imitates the movement of bubbles in sparkling water. The bubbles represents the elements of the data structure.

The bigger bubbles reach the top faster than smaller bubbles, and this algorithm works in the same way. It iterates through the data structure and for each cycle compares the current element with the next one, swapping them if they are in the wrong order.

It's a simple algorithm to implement, but not much efficient: on average, quadratic sorting algorithms with the same time complexity such as Selection Sort or Insertion Sort perform better. It has several variants to improve its performances, such as Shaker Sort, Odd Even Sort and Comb Sort.

Asymptotic Complexity

Average Time ComplexityΘ(n2)
Best Case Time ComplexityΩ(n)
Worst Case Time ComplexityO(n2)
Space ComplexityO(1)

FlowChart