AlgoViz

Bucket sort

medium 15 min

Bucket sort splits the value range into equal buckets, drops each value into its bucket with floor(x · k), sorts each small bucket and reads the buckets out in order.

Where it shows up

The same pattern appears across everyday software.

  • Post office mail sorting

    Letters go into bins by ZIP code prefix, each bin is sorted by street address, and the bins are collected in order. Far faster than sorting the whole sack at once.

  • External sorting of huge files

    When data does not fit in memory, a first pass writes values into range-based bucket files, each small enough to sort in memory, and the sorted files are appended in range order.

  • Distributed sorting (TeraSort, MapReduce)

    Big data sort jobs sample the keys to pick range boundaries, send each range to its own worker, sort locally and write the outputs in range order. That is bucket sort across machines.

  • Histograms and grade bands

    Grouping exam scores into bands or prices into ranges is the distribution step of bucket sort, often all that is needed before reporting.

  • Graphics and rendering

    Renderers bucket objects by depth range before drawing, so only the few objects in the same depth slice need precise ordering.