LabSorting algorithms
SortFusion
Watch eight sorting algorithms compare, swap and merge their way to order. Pause at any step, scrub the timeline, follow the pseudocode, or drop in your own numbers.
SortSpaceStep back←Step forward→Back to startRNew arraySSound onM
Press Space to sort, or step through with ← →.
- Unsorted
- Comparing
- Swap / write
- Pivot / minimum
- In final place
- Outside current range
Your own numbers
Commas or spaces between values, up to 200. Decimals and negatives work.
Live metrics
ReadyCompares
0
of 226
Swaps
0
of 127
Writes
0
of 0
Exec time
—
48 bars · Random · 498 steps
Quick Sort
Picks a pivot, partitions smaller values to its left and larger to its right, then recurses on each side.
unstablein-place
- Best
- O(n log n)
- Average
- O(n log n)
- Worst
- O(n²)
- Space
- O(log n)
quickSort(lo, hi):if lo ≥ hi: returnmove the middle item to hi as pivoti ← lofor j ← lo to hi − 1if a[j] < pivot: swap a[i], a[j]; i++swap a[i], a[hi] (pivot lands in place)quickSort(lo, i − 1); quickSort(i + 1, hi)
- Space
- Sort / pause
- ← →
- Step
- R
- Back to start
- S
- New array
- M
- Sound
Quick Sort
Picks a pivot, partitions smaller values to its left and larger to its right, then recurses on each side.
unstablein-place
- Best
- O(n log n)
- Average
- O(n log n)
- Worst
- O(n²)
- Space
- O(log n)
quickSort(lo, hi):if lo ≥ hi: returnmove the middle item to hi as pivoti ← lofor j ← lo to hi − 1if a[j] < pivot: swap a[i], a[j]; i++swap a[i], a[hi] (pivot lands in place)quickSort(lo, i − 1); quickSort(i + 1, hi)
- Space
- Sort / pause
- ← →
- Step
- R
- Back to start
- S
- New array
- M
- Sound