Bubble Sort Visualizer — Animated, Step-by-Step
Animated bubble sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs entirely in your browser.
Code examples
Ready-to-copy reference implementations. Free to use in your own projects and assignments.
How to use
- 1 Press Play to watch the array sort, or use Step to advance one comparison at a time.
- 2 Adjust Size for more or fewer bars, and Speed to slow the animation down.
- 3 Type your own numbers into Custom input and press Apply to sort a specific array.
- 4 Follow the highlighted pseudocode line and the live comparison / swap counters.
Why use this tool
- See exactly how adjacent comparisons and swaps bubble the largest value to the end each pass.
- Step forward and backward through every operation — no black box.
- Live metrics show why bubble sort is O(n²): comparisons grow with the array size.
- Runs entirely in your browser. No signup, no uploads.
Frequently asked questions
What is bubble sort?
Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. After each full pass the next-largest value is in its final position.
What is the time complexity of bubble sort?
O(n²) in the average and worst case because of the nested loops. Best case is O(n) when the array is already sorted — the optimized version detects no swaps and stops early.
Is bubble sort stable?
Yes. Equal elements keep their original relative order because it only swaps on a strict greater-than comparison.
When should I use bubble sort?
Almost never in production — it is a teaching algorithm. For real workloads use a built-in sort (Timsort / introsort). Bubble sort is valuable for understanding comparisons, swaps, and stability.
What is Bubble Sort Visualizer?
A Bubble Sort Visualizer is an interactive tool that animates the bubble sort algorithm, showing each adjacent comparison and swap as the largest values "bubble" to the end of the array. It highlights the active pseudocode line and counts comparisons and swaps so learners can see why bubble sort runs in O(n²) time.
Features
Step-by-step animation
Watch every comparison and swap with adjustable speed and custom input.
Complexity
Time: best O(n) (sorted, with early exit), average/worst O(n²). Space: O(1). Stable, in-place.
100% private
Runs entirely in your browser — nothing is uploaded.
Example
Input
[5, 1, 4, 2]
Output
Pass 1 → [1, 4, 2, 5]; Pass 2 → [1, 2, 4, 5] (sorted)
Common use cases
-
1
Learn sorting basics
See why adjacent-swap sorting is O(n²) and how swaps propagate.
-
2
Teach comparisons & swaps
Demonstrate the comparison/swap counts on small arrays.
-
3
Compare with faster sorts
Contrast bubble sort against merge or quicksort to motivate O(n log n).
Zerethon's bubble sort visualizer animates the algorithm step by step in your browser, showing each adjacent comparison and swap as larger values bubble to the end. Bubble sort runs in O(n²) time on average and worst case, O(n) on an already-sorted array with early-exit, and O(1) extra space; it is stable and in-place. It is mainly an educational algorithm — use a faster sort in practice.
- Category
- Algorithm
- Pricing
- Free
- Privacy
- Browser-based
- Signup
- Not required
References
- MIT OCW 6.006 — Introduction to Algorithms (CLRS) — MIT OpenCourseWare
- VisuAlgo — Sorting — VisuAlgo (NUS)
- Bubble sort — Wikipedia
Privacy
Your data never leaves your browser unless explicitly stated. Bubble Sort Visualizer runs entirely client-side — no server upload, no logging, no tracking of your input.
New to this? Read the step-by-step explanation with Big-O analysis: Learn Sorting Algorithms →
Compare
Related tools
Insertion Sort Visualizer
Animated insertion sort with step controls, speed, custom input, live comparison/write counters and pseudocode. Runs in your browser.
Open toolSelection Sort Visualizer
Animated selection sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs in your browser.
Open toolMerge Sort Visualizer
Animated merge sort with step controls, speed, custom input, live comparison/write counters and pseudocode. Runs in your browser.
Open toolQuick Sort Visualizer
Animated quicksort with pivot/partition highlights, step controls, speed, custom input, live counters and pseudocode. Runs in your browser.
Open toolBuild, share, and grow on Zerethon Social
Free signup. Earn points, collect achievements, and connect with creators worldwide.