Sort Target
Algorithm
Speed
Normal ~12s · 90 ms/step
Quicksort (Median3)(1978)
▶ Try this Source
O(n log n) ✗ Stable ✓ In-place
🔧 How it works

Selects the pivot as the median of the first, middle, and last elements, then performs the same in-place partition and recursion as basic Quicksort.

🎯 Key property

The median-of-three pivot is unlikely to be the extreme value, significantly reducing the probability of the O(n²) worst case on common patterns such as sorted or reverse-sorted input.

👁 Watch for
  • IndexRead three elements (first, middle, last) are read and compared to select the median; the chosen pivot is moved to a fixed position before partitioning begins
  • Compare same left-right partition scan as basic Quicksort; elements are tested against the selected median pivot
  • Swap same as basic Quicksort, elements on the wrong side are swapped across the partition boundary
Initial State
This is the array before sorting. Follow Quicksort (Median3) step by step.
Recursion Tree
[0..9)371952846
0 / 133 ops ( 0.0%) 0.0%
Sorting is
a spectacle.
Algorithms at work, in a daily vertical feed. Watch, play, challenge — and go deeper when you're ready.
Loading 0%
An unhandled error has occurred. Reload 🗙