Sponsor
Loading... Step 0 / 0
comparisons: 0
swaps: 0
Color Key:
Default
Comparing
Swapping
Pivot / Partition
Sorted
Execution Note: Initializing WASM engine...
0 0
Speed (ms): 200ms

Time Complexity

Best O(N)
Average O(N^2)
Worst O(N^2)

In the best case (already sorted), the algorithm only does one pass and finds no swaps. In the worst case (reverse sorted), it must do a pass for every element and swap every pair.

Space Complexity

Complexity O(1)

Bubble sort is an in-place sorting algorithm and requires only a constant amount of extra memory for the swap variable.