Bead sort

Initially, it may be helpful to imagine the beads suspended on vertical poles.

In Step 1, such an arrangement is displayed using n=5 rows of beads on m=4 vertical poles.

[notes 1] If we then allow the beads to fall, the rows now represent the same integers in sorted order.

The mechanism underlying bead sort is similar to that behind counting sort; the number of beads on each pole corresponds to the number of elements with value equal or greater than the index of that pole.

The function returns a new list rather than mutating the one passed in, but it can be trivially modified to operate in place efficiently.

Step 1: Suspended beads on vertical poles.
Step 2: The beads have been allowed to fall.