Bubble Sort Visualizer
Watch Bubble Sort compare and swap adjacent values with step controls, playback speed, operation metrics, and an interactive array.
Comma-separated numbers, up to 20 values.
Live operation
compare
Comparisons
1
Moves / writes
0
Confirmed sorted
0 / 5
Algorithm notes
What to watch for
Bubble Sort repeatedly scans adjacent pairs. A swap pushes the larger value rightward; after every pass, the far-right unsorted value is permanently placed.
Concept guide
Review the mental model, tradeoffs, and practical use cases after you experiment.
Bubble Sort Complete Info Card
Bubble Sort repeatedly compares adjacent elements and swaps them if they're in the wrong order, causing larger values to "bubble" to the end with each pass.
Algorithm Characteristics
Time Complexity (Best)
When array is already sorted
Time Complexity (Average)
Typical case with random data
Time Complexity (Worst)
When array is reverse sorted
Space Complexity
In-place sorting algorithm
Stable
Maintains relative order of equal elements
Adaptive
Can optimize for nearly-sorted inputs
Sorting Process Steps
Start with first two elements
Compare and swap if out of order
Move to next pair, repeat to end
Largest element "bubbles" to end
Repeat process for n-1 passes
Optimize with early exit if no swaps
Optimization Techniques
Early Termination
Stop if no swaps occur in a pass
Reduced Passes
Ignore already sorted elements
When to Use
- •Educational purposes (simple to understand)
- •Nearly sorted small datasets
- •Memory-constrained environments
When to Avoid
- •Large datasets (use QuickSort/MergeSort)
- •Performance-critical applications
- •When stability isn't required