5

Configure inputs and press Visualize to begin.

64
34
25
12
22
11
90
45
Default
Comparing
Swap
Pivot
Sorted
Found
Pseudocode & Implementations
1 approach

Sort digit-by-digit from least significant to most significant. Uses Counting Sort as a stable subroutine for each digit pass.

RADIX-SORT(A):
  maxVal = max(A)
  k = number of digits in maxVal

  FOR place = 1, 10, 100, ... (each digit position):
    COUNTING-SORT-BY-DIGIT(A, place)

COUNTING-SORT-BY-DIGIT(A, place):
  n = length(A)
  output = array of size n
  count  = array of size 10, all zeros

  // Count occurrences of each digit
  FOR i = 0 TO n-1:
    digit = (A[i] / place) % 10
    count[digit]++

  // Cumulative count
  FOR i = 1 TO 9:
    count[i] += count[i-1]

  // Build output (traverse right-to-left for stability)
  FOR i = n-1 DOWNTO 0:
    digit = (A[i] / place) % 10
    output[count[digit]-1] = A[i]
    count[digit]--

  COPY output INTO A
Complexity Analysis

Time Complexity

Best Case
PolynomialO(nk)
Average
PolynomialO(nk)
Worst Case
PolynomialO(nk)
Space (aux)
PolynomialO(n+k)
StableExtra spacenon-comparisonlinearstable
About

Non-comparison sort that processes digits from least to most significant. Groups numbers into buckets for each digit position.

Key Insight

Breaks the comparison-based O(n log n) lower bound by exploiting structure in the data.

Use Cases

Integer sortingString sortingFixed-length keysWhen k is small