Chapter 10 · Simulation

String Sorting: LSD Radix Sort

← Chapter 10

Current Array

Buckets

Ready.

String Sorting: LSD Radix Sort

Strings are sorted stably with buckets, from the rightmost character to the leftmost.

How to use

  • Enter comma-separated strings (up to 12 strings of up to 10 characters) and press Load Data.
  • Step performs one pass: each string goes into the bucket of its character at the current position, then the buckets are concatenated in character order. Auto Play runs the remaining passes; Reset reloads the input.
  • The highlighted column is the position used in the last pass; green columns were processed earlier.

Different lengths

If the strings differ in length, shorter ones are padded on the right internally with a space character (shown as ·) so that every position can be processed. Since the space sorts before every character, a string comes before its extensions (for example "be" before "bed"), which is lexicographic order.

Why does it work?

Each pass is a stable distribution: strings that have the same character at the current position keep the order produced by earlier passes. After the pass at position 0, the strings are sorted by all positions.

Complexity

MeasureValue
TimeO(W · (n + R)) for n strings of width W and an alphabet of size R
Extra memoryO(n + R)
StableYes