Sort Target
Algorithm
Speed
Normal ~12s · 34 ms ×3
Ipnsort(2024)
▶ Try this Source
O(n log n) ✗ Stable ✓ In-place
🔧 How it works

Sorts inputs of at most 20 elements with a guarded insertion sort, checks whether a single pre-sorted run covers the whole input (reversing it when strictly descending), then quicksorts with a pseudo-median pivot sampled as in Glidesort, falling back to Heapsort after 2⌊log₂ n⌋ partitions.

🎯 Key property

The partition is a branchless Lomuto loop paired with a cyclic permutation — two moves per element and no data-dependent branch on the classification. A pivot equal to the left-ancestor pivot triggers an equal-partition pass that removes the whole pivot-equal block from the recursion, giving O(n log k) behavior for k distinct values. The algorithm behind Rust's unstable sort since 1.81.

👁 Watch for
  • Compare (run detection) a single scan up front decides whether the input is already one ascending or strictly descending run; partial runs are deliberately left to the stable sort (Driftsort)
  • IndexWrite (partition) elements rotate through one gap slot instead of being swapped pairwise, so each element moves exactly twice regardless of which side it belongs to
  • Compare + Swap (small sort / Heapsort fallback) partitions of at most 32 elements are finished by 9- and 13-element optimal sorting networks extended with insertion and a bidirectional merge; too many bad pivots switch to Heapsort's sift-down swaps
Initial State
This is the array before sorting. Follow Ipnsort step by step.
Recursion Tree
[0..48)318441732639124721635144228119461033245411637229481122457301843259381534427402013362332
0 / 1,046 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 🗙