INFO

Compares adjacent elements and swaps them if in wrong order. Simple but O(n²).

TIME: O(n²)SPACE: O(1)

VISUALIZATION

Comp0
Swap0
0ms
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
50
Unsorted
Active
Comparing
Sorted
Pivot

Algorithm Details

Bubble Sort

Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they're in the wrong order. The pass through the list is repeated until the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. While it's simple to understand and implement, it's not efficient for large datasets with its average and worst-case time complexity of O(n²).

Complexity Analysis

Best CaseO(n)
Time ComplexityO(n²)
Average CaseO(n²)
Space ComplexityO(1)
Worst CaseO(n²)