Sort Target
Algorithm
Speed
Normal ~12s · 32 ms ×6
MSD Radix sort (b=4)(1954)
▶ Try this Source
O(nk) ✓ Stable ✗ In-place
🔧 How it works

Sorts integers digit by digit from the most significant to the least significant 2-bit group, distributing elements into up to four buckets per pass and then recursively sorting each bucket for the next digit.

🎯 Key property

Processing the most significant digit first allows early termination, sub-buckets whose elements already agree on all remaining digits need no further work, giving it adaptive behaviour similar to a comparison sort.

👁 Watch for
  • IndexRead each element's current most-significant remaining digit is extracted by a bitwise operation; the digit determines which of the four buckets the element enters
  • IndexWrite elements are placed into their digit buckets; each bucket is then processed recursively for the next digit position
  • End of pass sub-buckets of size 1 terminate immediately; watch small sub-buckets stop early while larger ones recurse deeper into finer digit positions
Initial State
This is the array before sorting. Follow MSD Radix sort (b=4) step by step.
Main Array
15
0
51
1
64
2
89
3
53
4
46
5
329
6
3
7
79
8
61
9
309
10
23
11
95
12
63
13
27
14
74
15
70
16
317
17
302
18
10
19
85
20
94
21
7
22
52
23
26
24
20
25
12
26
305
27
311
28
77
29
325
30
73
31
28
32
2
33
35
34
13
35
44
36
21
37
39
38
321
39
69
40
8
41
308
42
56
43
315
44
99
45
72
46
40
47
312
48
84
49
59
50
82
51
19
52
303
53
306
54
87
55
41
56
14
57
80
58
310
59
301
60
81
61
100
62
76
63
48
64
62
65
18
66
29
67
83
68
25
69
17
70
33
71
24
72
22
73
322
74
96
75
88
76
1
77
318
78
45
79
324
80
4
81
97
82
37
83
304
84
57
85
60
86
9
87
328
88
307
89
65
90
34
91
93
92
300
93
71
94
58
95
90
96
36
97
92
98
32
99
314
100
38
101
91
102
326
103
16
104
327
105
319
106
5
107
11
108
54
109
313
110
47
111
68
112
86
113
30
114
42
115
55
116
50
117
320
118
78
119
31
120
67
121
98
122
316
123
323
124
49
125
66
126
6
127
43
128
75
129
BucketsScatter— bits 30-31Pass 1Range [0..129]
0
1
2
3
0 / 2,223 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 🗙