Skip to content
PixelCursor(opens in a new tab)
Computer Science

Sorting Visualizer

Watch nine sorting algorithms work, step by step

Algorithm
40 elements
Speed
  • Slow · 1 s
  • Medium · 0.4 s
  • Fast · 0.1 s
  • Very fast · 25 ms
  • Maximum · 5 ms
Playback
Ready

Ready. Press Play, or step through Bubble Sort.

  • Compared
  • Swapped or written
  • Selected or pivot
  • In its final place

Your runs

Runs finished0
Tried0of 9
Comparisons watched0

Play a run to the end and it counts here, saved on this device only.

Bubble Sort

Walks through the list again and again, compares neighbours and swaps them when they are in the wrong order, until a pass needs no swap.

Best
O(n)
Average
O(n²)
Worst
O(n²)
Memory
O(1)
StableIn placeComparison-based

Strengths

  • Very simple to write
  • Needs no extra memory
  • Stable
  • Notices when the list is already sorted

Weaknesses

  • Quadratic time, O(n²)
  • Writes more than Selection Sort
  • Impractical for large lists

Compare all algorithms

Runs every algorithm on the same 40 values and counts the work each one does.

Bogo Sort sits this one out: it would shuffle more or less forever.

About this tool

  • Algorithm complexity

    Big O notation describes how the work grows with the input: twice the values can mean twice, four times or barely more steps.

  • Sorting in practice

    Databases, search engines and spreadsheets sort constantly; real libraries mix methods, for example Insertion Sort for short runs.

  • Stability and adaptivity

    A stable sort keeps equal values in their original order; an adaptive one gets faster when the input is already partly sorted.

Keyboard

Space
Play or pause
←→
Step back or forward
R
Reset the run
S
Shuffle the values