Bucket sort and radix sort

Published

2023-08-05

Bucket sort and radix sort work using a distribute and collect approach without making comparisons. In appropriate use cases, these can be faster than \mathcal{O}(n \log n) algorithms like quicksort or merge sort. But they do not have the same breadth of applicability as do quicksort or merge sort or other comparison-based algorithms.

For example, bucket sort requires that the values of its input be more-or-less uniformly distributed. Bucket sort does not work well with data that aren’t close to being uniformly distributed.

Radix sort requires that values can be sorted lexicographically. This makes it suitable for integers and strings, but it won’t work for floating point or other types that cannot be sorted lexicographically.

Here we implement radix sort for non-negative integers in C++.

Supplemental materials:

Comprehension check:

  1. True or false? Bucket sort and radix sort are general-purpose sorting algorithms.
  2. True or false? Bucket sort and radix sort are distribute-and-collect algorithms.
  3. Radix sort works without performing _________________.
  4. True or false? Given suitable inputs, bucket sort and radix sort can outperform comparison-based algorithms.
  5. Radix sort requires that elements can be sorted in ____________________ order.
  6. Bucket sort works best when values are _______________ distributed.

Answers: ʎlɯɹoɟᴉun / ɔᴉɥdɐɹƃoɔᴉxǝl / ǝnɹʇ / suosᴉɹɐdɯoɔ / ǝnɹʇ / ǝslɐɟ

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

All materials copyright © 2020–2023, The University of Vermont. All rights reserved.