Bucket Sort


Generally you can’t do better than with binary comparison.

However, can do better if the structure of the data is known, which allows to sort it into buckets in a single operation.

For example:

  • Integers (buckets on digits), a.k.a. radix sort.
  • Words (buckets on letters).

The for bucket for on a given number of digit is but also in the number of digits.

It is .

Example

 

Start by sorting on the least significant digit:

BinsSublist
0
1
2472 432
3
4254 534 654
5
6
7477
8
9459 649 239

Then we go to the second digit, preserving ordering from first sort:

BinsSublist
0
1
2
3432 534 239
4649
5654 254 459
6
7472 477
8
9

And then finally on the third digit, again preserving ordering:

BinsSublist
0
1
2239 254
3
4432 459 472 477
5534
6649 654
7472 477
8
9