How to Use the Sorting Visualizer
- Pick a sort from the row of buttons above the bars. Bubble Sort is selected to start.
- Set up the array: drag the size slider, press Shuffle, or open Presets for sorted, reversed, nearly sorted or few-unique data.
- Press Run to compute the steps, then Play to watch the whole run, or step forwards and backwards one step at a time. The speed control slows things down.
- Read the highlighted line in the pseudocode panel. It shows exactly which line of the algorithm produced the step you are looking at.
Sorting Algorithms You Can Visualize
| Algorithm | Average / worst time | Extra space | Stable | Input to try |
|---|---|---|---|---|
| Bubble Sort | O(n²) / O(n²) | O(1) | Yes | Sorted |
| Selection Sort | O(n²) / O(n²) | O(1) | No | Sorted |
| Insertion Sort | O(n²) / O(n²) | O(1) | Yes | Nearly Sorted |
| Merge Sort | O(n log n) / O(n log n) | O(n) | Yes | Random |
| Quick Sort | O(n log n) / O(n²) | O(log n) avg | No | Sorted |
- What to watch in Bubble Sort
- The largest remaining bar drifts to the right on every pass. On sorted input one swap-free pass ends the run.
- What to watch in Selection Sort
- Exactly one value is placed per pass, and the swap counter never passes n − 1. On sorted input it makes no swaps but just as many comparisons.
- What to watch in Insertion Sort
- Most values never move; only the few out-of-place ones slide left, so the run is far shorter than on reversed input.
- What to watch in Merge Sort
- The array splits into halves, then the halves merge back in order. The step count barely changes with the input.
- What to watch in Quick Sort
- Each pivot (the last element) splits the bars into smaller and larger. Sorted input makes every split lopsided.
Which Sorting Algorithm Should You Watch First?
- Bubble Sort first: it only compares two neighbours, so every step is easy to follow.
- Selection Sort next, to see a sort that does few swaps but always makes the same number of comparisons.
- Insertion Sort on nearly sorted data, to see why a quadratic sort is still used inside real library sorts.
- Merge Sort and Quick Sort last: the two O(n log n) approaches, one that always splits evenly and one that depends on its pivot.
Choosing a sort for real code? The sorting algorithms cheat sheet has the full best, average and worst-case table and a guide to picking one.
Compare Sorting Algorithms Side by Side
Each guide puts two sorts head to head and ends with a clear verdict on when to use which.
Sorting Visualizer FAQ
What is a sorting algorithm visualizer?
It is a tool that draws an array as bars and animates what a sorting algorithm does to it, one comparison or swap at a time. Seeing the moves makes it much easier to understand why one algorithm needs far more steps than another on the same data.
Which sorting algorithm is the fastest?
There is no single fastest sort. Quick Sort is usually quickest on random data but slows to O(n²) on bad input, Merge Sort is O(n log n) on every input but needs extra memory, and Insertion Sort wins on small or nearly sorted arrays. Run each one with the same preset here and compare the step counters.
Why is bubble sort so slow?
Bubble Sort only ever swaps neighbouring values, so a value far from its final position needs many passes to get there. On random data that adds up to roughly n²/2 comparisons, which grows quickly: at most 45 for 10 items but around 5,000 for 100.
Which of these sorts are stable?
Bubble, Insertion and Merge Sort are stable: values that compare equal keep their original order. Selection and Quick Sort are not, because their long-distance swaps can jump one equal value past another. Stability matters when you sort records by one field after already sorting them by another.
Is VizStep free?
Yes. VizStep is free for personal, educational and classroom use, and every visualizer works without an account or sign-up.