Skip to content
CoreSource checked

Radix Sort

Sorts values by processing one digit or character position at a time.

Quick Facts

Compact metadata for implementation and discovery.

Category
Sorting
Difficulty
Intermediate
Family
Distribution Sort
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
0
Relationships
4
Code example
Ready
Visualization
Ready

Overview

Radix Sort repeatedly groups values by digit position, often using a stable counting sort for each pass.

Core Concepts

integer key rangestable orderingdistribution sortordering invariantcomparison or key rulearray rearrangement

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(d(n + k))

Average

O(d(n + k))

Worst

O(d(n + k))

Space

O(n + k)

When to Use

  • Use Radix Sort when you need to process values by digit or character.
  • Use it for sorting integers with inputs like integer or fixed-width key array.
  • Use it when ordered output makes later searching, ranking, or presentation easier.
  • Use it when the Distribution Sort tradeoff is acceptable for the problem size.

When Not to Use

  • Avoid it when values are not bounded integers or cannot be mapped cleanly to integer keys.
  • Avoid it when a partial order, top-k result, or streaming approach would answer the question with less work.
  • Avoid it when the required output is not sorted array.

What It Does

  • Processes values by digit or character
  • Uses stable passes to build full order

Use Cases

  • Sorting integers
  • Sorting fixed-width strings
  • Large batches with bounded key sizes

Inputs

  • Integer or fixed-width key array
  • Base or digit width

Outputs

  • Sorted array

Pseudocode

  1. 1.Choose the order of digit positions
  2. 2.For each digit position:
  3. 3.Group or sort values by that digit using a stable method
  4. 4.Carry the order into the next digit pass
  5. 5.Return the fully ordered values

Canonical Example

Input
values = [5, 1, 4, 2]
Output
values = [1, 2, 4, 5]
Explanation
Radix Sort: The algorithm reorders the values so later operations can read them in ascending order.

Implementation Notes

  • Keep the input contract explicit: Integer or fixed-width key array; Base or digit width.
  • Use this step as the implementation spine: Choose the order of digit positions.
  • Then preserve the next state change: For each digit position:.
  • Test with empty input, one item, duplicates, and already sorted values.

Common Pitfalls

  • Radix Sort depends on stable digit passes to preserve earlier ordering work.
  • Assuming stability without checking the implementation can reorder equal keys.
  • Forgetting to define how equal values and custom comparison rules should behave.
  • Returning sorted array without handling empty, invalid, or boundary inputs.

Interactive Mechanism Walkthrough

Array Partition & Ordering Trace

Show values being regrouped by each digit from one pass to the next.

38
[0]
14
[1]
52
[2]
23
[3]
61
[4]
19
[5]
44
[6]
29
[7]
Step 1 of 5: Choose the order of digit positions
digit-passes

Notes

Radix Sort operates in O(d(n + k)) time and O(n + k) space within the Distribution Sort family. Often compared with Counting Sort and Quick Sort.

Sources (1)

What each reference supports for this entry.

Introduction to Algorithms (CLRS)

Book

Textbook support for Radix Sort invariants, recurrences, relaxation rules, or asymptotic analysis.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Radix sort uses stable counting-style passes to order keys digit by digit.

Related Algorithms

Tags

Integer DataStable SortClassic