5

Configure inputs and press Visualize to begin.

64
34
25
12
22
11
90
45
Default
Comparing
Swap
Pivot
Sorted
Found
Pseudocode & Implementations
2 approaches

Compare every adjacent pair in each pass. No optimization — always does n×(n-1)/2 comparisons.

BUBBLE-SORT(A):
  n = length(A)
  FOR i = 0 TO n-2:
    FOR j = 0 TO n-i-2:
      IF A[j] > A[j+1]:
        SWAP(A[j], A[j+1])
  RETURN A
Complexity Analysis

Time Complexity

Best Case
LinearO(n)
Average
QuadraticO(n²)
Worst Case
QuadraticO(n²)
Space (aux)
ConstantO(1)
StableIn-placecomparisonsimplestable
About

Repeatedly compares adjacent elements and swaps them if out of order. The largest element 'bubbles up' to the correct position each pass.

Key Insight

After each pass, the largest unsorted element is guaranteed to be in its final position.

Use Cases

Educational purposesSmall nearly-sorted datasets