V

Algorithm Visualizer

ZHEN
Share on WeiboShare on XGitHub repositoryAuthor website
Learning ToolsAlgorithm Complexity ReferenceAlgorithm Learning Paths
Data StructuresArrayLinked ListStackQueue and DequeBinary Search TreeBinary HeapHash TableGraphTrieDisjoint Set UnionLRU CacheSkip ListSegment TreeB+ TreeBloom FilterFenwick Tree
SortingBubble SortCocktail Shaker SortBitonic SortSelection SortInsertion SortBinary Insertion SortShell SortMerge SortTop-Down Merge SortQuick SortThree-Way Quick SortDual-Pivot Quick SortHeap SortCounting SortRadix SortBucket Sort
Graph AlgorithmsDijkstra's Shortest PathKruskal's Minimum Spanning TreePrim's Minimum Spanning TreeBellman-Ford Shortest PathsTopological SortFloyd-WarshallStrongly Connected Components2-SATMaximum FlowBipartite MatchingLowest Common AncestorEulerian Path
Dynamic ProgrammingEdit Distance0/1 KnapsackUnbounded KnapsackLongest Common SubsequenceLongest Increasing SubsequenceCoin ChangeStone MergingTraveling Salesperson DPTree Dynamic ProgrammingDigit DPRerooting DP
Backtracking and SearchN-QueensSubsetsPermutationsCombination SumMaze Solving with DFSNumber of IslandsWord SearchSudoku SolverA* Search
StringsKMP String MatchingRabin-Karp String MatchingBoyer-Moore String MatchingManacher's Longest Palindromic SubstringSuffix ArrayLCP ArrayAho-Corasick AutomatonZ Function
Math and Number TheorySieve of EratosthenesLinear SieveEuclidean AlgorithmBinary ExponentiationExtended Euclidean AlgorithmChinese Remainder TheoremEuler's Totient FunctionMiller-Rabin Primality TestFast Fourier TransformPollard's Rho Factorization
Computational GeometryConvex HullRotating CalipersClosest Pair of PointsLine Segment IntersectionBentley-Ottmann Sweep Line
SearchingBinary SearchLower and Upper BoundSearch in a Rotated Sorted ArrayBinary Search on the AnswerTernary Search

Radix Sort

Distribute values by one digit at a time and collect buckets stably from least to most significant digit.

Core idea

Process digits from least to most significant. Each stable bucket pass orders values by one more digit while preserving the order established by all lower digits.

Read the visualization

The active place value selects one of ten buckets for every number. Collection drains buckets from zero through nine without changing order inside a bucket.

42
7
25
63
18
31
56
9
0
0
0
1
0
2
0
3
0
4
0
5
0
6
0
7
0
8
0
9

Begin a stable bucket pass for the next base-ten digit.

1function radixSort(a: number[]): number[] {
2 const maxVal = Math.max(...a);
3 const passes = String(maxVal).length;
4 for (let d = 0; d < passes; d++) {
5 const buckets: number[][] = Array.from({ length: 10 }, () => []);
6 const div = 10 ** d;
7 for (const x of a) buckets[Math.floor(x / div) % 10].push(x);
8 let w = 0;
9 for (const bucket of buckets)
10 for (const x of bucket) a[w++] = x;
11 }
12 return a;
13}
n8
round1/2
digitones digit
phasestart
i-
w-
1 / 35

Complexity and tradeoffs

Time: O(d(n+k)). Space: O(n+k). Avoids comparisons when keys have d bounded digits over radix k; every digit pass must be stable.

Invariant: After processing d digits, the array is stably sorted by the d least significant digits.

Where it fits

Radix Sort is effective for bounded integers, fixed-width identifiers, and strings with a controlled alphabet. Extra storage and multiple full passes make it unsuitable for arbitrary comparison keys.