Sort Target
Algorithm
Speed
Normal ~12s · 34 ms ×7
Driftsort(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; otherwise scans for pre-sorted runs with a √n acceptance threshold (capped at 64), reverses strictly descending runs, and schedules the merges with a Powersort merge tree.

🎯 Key property

Adjacent unsorted runs are merged only logically — concatenated while they still fit the scratch buffer — so fully random input degenerates into one large out-of-place stable quicksort while structured input takes the merge path. A pivot equal to the left-ancestor pivot triggers an equal-partition pass, giving O(n log k) behavior for k distinct values. The algorithm behind Rust's stable sort since 1.81.

👁 Watch for
  • Compare the run-detection scan accepts a run only once it reaches √n elements, so short accidental runs are ignored and the segment becomes an unsorted run instead
  • RangeCopy the stable partition writes the left side to the front of the buffer and the right side to the back, then copies both groups back; a physical merge instead copies the shorter run out first
  • IndexWrite sub-slices of at most 32 elements are finished by stable 4/8-element selection networks plus guarded insertion, joined by a bidirectional merge
Initial State
This is the array before sorting. Follow Driftsort step by step.
Main Array
25
0
26
1
27
2
28
3
29
4
30
5
31
6
32
7
24
8
23
9
22
10
21
11
20
12
19
13
18
14
17
15
33
16
34
17
35
18
36
19
37
20
38
21
39
22
40
23
16
24
15
25
14
26
13
27
12
28
11
29
10
30
9
31
41
32
42
33
43
34
44
35
45
36
46
37
47
38
48
39
8
40
7
41
6
42
5
43
4
44
3
45
2
46
1
47
57
48
58
49
59
50
60
51
61
52
62
53
63
54
64
55
56
56
55
57
54
58
53
59
52
60
51
61
50
62
49
63
RunsDetect 0 runs on stack
Waiting for run detection…
0 / 2,450 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 🗙