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

A stable Quicksort that swaps the roles of the main array and a scratch buffer at each recursion level, routing elements directly into their final regions so no copy-back is needed. Falls back to bottom-up merge sort when the recursion budget runs out.

🎯 Key property

The dest-swap technique eliminates copy-back overhead, achieving the same ping-pong effect as merge-sort-based algorithms. The merge sort fallback provides an O(n log n) worst-case guarantee.

👁 Watch for
  • Compare each element is compared against the pivot to route it to one of four groups; a second comparison on the geq side resolves equal elements
  • IndexWrite all four groups are written directly into destination and scratch regions in a single scan with no intermediate buffer
  • RangeCopy at the base case or fallback, split input halves are assembled into the destination before bottom-up merge sort takes over
Initial State
This is the array before sorting. Follow Quicksort (Destswap Stable) step by step.
Recursion Tree
[0..9)371952846
0 / 119 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 🗙