Sort Target
Algorithm
Speed
Normal ~12s · 42 ms/step
Spreadsort(2002)
▶ Try this Source
O(n√(log n)) ✗ Stable ✗ In-place
🔧 How it works

Based on Boost C++ integer_sort. Checks for sorted input while finding min and max, computes value-proportional bucket indices, and permutes elements in-place via a 3-way swap loop. Each bucket is evaluated against a dynamic threshold to decide between further spreading or falling back to PDQSort.

🎯 Key property

Arrays under 1000 elements skip spreading and fall back to PDQSort. The radix width per level can consume all remaining bits in one pass when the range is small enough. Dynamic fallback thresholds consider the remaining bit range, giving finer control than subproblem size alone.

👁 Watch for
  • What this page actually shows at 31 elements the 1000-element minimum is not met, so the steps below are PDQSort, not spreading. There is no array size that both triggers spreading and stays readable — the delegation itself is Boost's design decision, and seeing it is the point
  • Compare (sorted detection) the initial scan walks the sorted prefix; if the entire range is in order the algorithm returns immediately
  • IndexRead + IndexWrite (3-way swap) each element is swapped to its target bucket position; displaced elements that also belong elsewhere involve a 3-element rotation to reduce copies
  • Fallback each bucket's count is checked against a dynamic threshold; small buckets use PDQSort, tiny ones (16 or fewer) use InsertionSort
Initial State
This is the array before sorting. Follow Spreadsort step by step.
Main Array
5
0
1
1
7
2
3
3
6
4
2
5
4
6
8
7
13
8
9
9
15
10
11
11
14
12
10
13
12
14
16
15
21
16
17
17
23
18
19
19
22
20
18
21
20
22
24
23
29
24
25
25
31
26
27
27
30
28
26
29
28
30
0 / 286 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 🗙