Algorithm visualizer
Watch sorting, searching, stacks and queues run one step at a time.
Between 5 and 60 numbers. Changing it makes a new array.
Bubble sort
- Comparing
- Swapping
- Written (merge)
- Pivot / current minimum
- Sorted
- Found
- Dimmed = outside the range being worked on
Show the values as text
Reduced motion is on: animations are off and playback starts slow. Use the step buttons or the arrow keys to move one step at a time.
How to read this
- Sorting: each bar is a number and its height is its value. Searching: each box is a number with its index below.
- States use a pattern, a symbol and a colour (see the legend):
?striped = being compared,⇄cross-hatched = swapped,↓lined = written (merge),◆outlined = pivot or current minimum,✓dotted = sorted,★= found. - Small labels under the bars are pointers:
i,j,min,lo,mid,hi,L/R(left and right run). They are hidden when there are too many bars; the step sentence still says what is happening. - Dimmed items are outside the range currently being worked on (binary search: eliminated; quick and merge sort: outside the current part).
- Counters count comparisons, swaps and array writes (a swap is two writes). The highlighted line in the pseudocode is the line being run.
- Merge sort shows the range being merged as: merged so far, then what is left of the left run, then the right run. That keeps the array a permutation at every step. A real merge copies into a temporary buffer and writes back one value at a time, and the counters count it that way.
- Binary search needs sorted data, so the page sorts a copy first (a clearly labelled pre-step that is not counted).
- Keyboard (when focus is not in a text box): Space play / pause, ← step back, → step forward.
Compare algorithms
| Algorithm | Comparisons | Swaps | Writes |
|---|
Each sort runs silently on the same array. Click a row to watch that algorithm. Merge sort never swaps: it writes merged values back into the array.