Sort Target
Algorithm
Speed
Normal ~12s · 36 ms ×2
Quicksort (3-way)(1976)
▶ Try this Source
O(n log n) ✗ Stable ✓ In-place
🔧 How it works

Selects a single pivot (median of three) and partitions the array into three regions in one scan: less than, equal to, and greater than the pivot. Only the non-equal regions recurse.

🎯 Key property

Grouping equal elements costs O(n) per partition but eliminates all further work on them. In the all-equal case it finishes in a single O(n) scan with no recursive calls. Unlike Dual-Pivot, which uses two pivots to optimise random-data throughput, 3-way targets duplicate-heavy data with one pivot.

👁 Watch for
  • Compare each element is compared against the pivot once; equal elements simply advance the scan pointer with no swap
  • Swap only less-than and greater-than elements are swapped; equal elements stay put, so the swap count drops when duplicates are common
  • End of partition the equal-region boundaries lt and gt are fixed; only [left, lt-1] and [gt+1, right] are passed to recursion
Initial State
This is the array before sorting. Follow Quicksort (3-way) step by step.
Recursion Tree
[0..48)318441732639124721635144228119461033245411637229481122457301843259381534427402013362332
0 / 673 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 🗙