Quicksort vs Merge sort
Quicksort vs merge sort compared — speed, memory, stability and worst case, with interactive visualizers.
Quicksort partitions around a pivot in place and is usually the fastest in practice; merge sort splits and merges with guaranteed O(n log n) and stability, at the cost of extra memory.
Quicksort vs Merge sort at a glance
| Quicksort | Merge sort | |
|---|---|---|
| Average time | O(n log n) | O(n log n) |
| Worst case | O(n²) | O(n log n) |
| Memory | In place | O(n) extra |
| Stable | No | Yes |
When to use Quicksort
Use quicksort as a fast in-place default for arrays where worst case is unlikely.
When to use Merge sort
Use merge sort when you need guaranteed O(n log n), stability, or are sorting linked lists.
Tools for Quicksort & Merge sort
Quick Sort Visualizer
Animated quicksort with pivot/partition highlights, step controls, speed, custom input, live counters and pseudocode. Runs in your browser.
Open toolMerge Sort Visualizer
Animated merge sort with step controls, speed, custom input, live comparison/write counters and pseudocode. Runs in your browser.
Open toolHeap Sort Visualizer
Animated heap sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs in your browser.
Open toolBubble Sort Visualizer
Animated bubble sort with step controls, speed, custom input, live comparison/swap counters and pseudocode. Runs entirely in your browser.
Open toolQuicksort vs Merge sort
Why is quicksort often faster than merge sort?
Quicksort sorts in place with good cache locality and low overhead, so it usually beats merge sort in practice — even though merge sort guarantees O(n log n) and quicksort can hit O(n²) with poor pivots.