Levelup

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.
2 to 60 whole numbers from 1 to 999, separated by commas.

Bubble sort

  • Comparing
  • Swapping
  • Written (merge)
  • Pivot / current minimum
  • Sorted
  • Found
  • Dimmed = outside the range being worked on
Show the values as text

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

Comparisons, swaps and writes for each sorting algorithm on the current array. Select a row to switch to that algorithm.
AlgorithmComparisonsSwapsWrites

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.