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

Picks two pivots p1 ≤ p2 and partitions the array into three regions in a single pass: elements < p1, elements between p1 and p2, and elements > p2; each region is then sorted recursively.

🎯 Key property

Three partitions instead of two reduce average comparisons by roughly 5/9 compared to single-pivot Quicksort; this exact algorithm is used by Java's Arrays.sort for primitive types.

👁 Watch for
  • Compare each element is compared against both pivots to determine which of the three regions it belongs to; two comparisons per element rather than one
  • Swap elements are moved to their correct region; at the end of each step both pivots are placed at their final sorted positions, fixing two positions at once
  • End of partition two pivot positions are fixed simultaneously, splitting the remaining work into three independent sub-problems
Initial State
This is the array before sorting. Follow DualPivot Quicksort step by step.
Recursion Tree
[0..48)318441732639124721635144228119461033245411637229481122457301843259381534427402013362332
0 / 519 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 🗙