🚥Sorting Algorithm Visualizer - Animated Sorts & Race Mode
See how sorting algorithms really work with an animated bar chart. Fourteen algorithms are built in: bubble, cocktail shaker, comb, selection, insertion, Shell sort (Ciura gaps), merge sort, quicksort with both Lomuto and Hoare partitioning, heap sort, counting sort, LSD radix sort, bucket sort and a simplified Timsort. Each one is written as a generator that emits an event for every comparison, swap or write, and the animation replays those events one by one, so every frame matches the real code exactly: yellow means comparing, red means swapping or writing, blue means reading, and a green sweep marks the finished array. Set the array size (up to 1,000 elements), the input (random, sorted, reversed, nearly sorted or few unique values) and the speed, or pause and step through one event at a time, while live counters track comparisons, swaps, writes and total steps. Turn on sound to hear each element’s value as pitch and pick up the rhythm of each algorithm. Race mode runs 2–4 algorithms side by side on the same data and ranks them as they finish — a vivid way to see O(n²) versus O(n log n), or how quicksort copes with many duplicates. A table at the bottom compares best, average and worst-case time, extra space and stability for every algorithm.
Free · No sign-up · Runs in your browserLast updated:
How to use Sorting Algorithm Visualizer
- 1Pick an algorithm (or switch to race mode and choose 2–4), then set the array size and input pattern
- 2Press play to watch, adjust the speed, or pause and step through events
- 3Compare the comparison, swap and write counts and the finishing order, and check the complexity table
FAQ
- Which sorting algorithm is the fastest?
- No algorithm wins everywhere. On random data quicksort, merge sort and heap sort are all O(n log n), and quicksort usually wins thanks to its small constant factor. On nearly sorted data insertion sort and Timsort approach O(n), and for integers in a small range counting or radix sort run in linear time. Try different inputs in race mode to see the differences for yourself.
- What’s the difference between Lomuto and Hoare partitioning?
- Lomuto uses the last element as the pivot and scans left to right, swapping smaller elements to the front — simple, but it does many swaps and degrades with lots of duplicates. Hoare moves two pointers towards each other and swaps only out-of-place pairs, typically doing less than half as many swaps and handling duplicates better. The Lomuto version here uses median-of-three so already-sorted input doesn’t degrade to O(n²).
- What is a stable sort?
- A stable sort keeps equal elements in their original order. If you sort a list by name and then stably by score, people with the same score stay in name order. Merge, insertion, bubble, counting, radix and Timsort are stable; quicksort, heap sort, selection sort and Shell sort are not.
- Why do counting and radix sort make zero comparisons?
- They don’t sort by comparing pairs: counting sort tallies how often each value occurs and writes them back in order, and radix sort distributes values into buckets digit by digit. That lets them sidestep the Ω(n log n) lower bound for comparison sorts and run in linear time when the value range or number of digits is small — paid for with extra memory, reads and writes, all shown in the counters.