Hacker News new | past | comments | ask | show | jobs | submit login

The correct sort for that situation is a most-significant-digit-first variant of a radix sort. Arrange the documents into 10 piles based on hundreds digit. Pile up all of them except the zeroes, then sort the zeroes recursively. Then pull the next segment out of the pile, and sort it recursively. And so on.

This is often the most efficient way to sort physical items when you have a constrained range and working space, without custom equipment.

And yes, it really helps to know about variants like the American Flag Sort to realize that you can mix and match algorithm properties. AFS is an in-place sort, which is horribly inefficient for physical objects, but the observation that you can do a radix sort in MSD order is a refreshing additional observation vs "radix sort is always LSD first" the way card sorters work.




Some of my friends are postal workers and have described their mail sorting to be roughly this. It's not a general algorithm though, there is knowledge of their route weaved in. So the most significant bit would be the street name, but they'd remember houses 42+ are earlier in the route and direct them to a different bucket. For this reason the person delivering the mail also sorts it.

Computer science isn't directly applicable because we generally deal with general purpose algorithms, but I wonder how often their work is applicable to us, how often could we see huge improvements by using a specialized for the purpose sorting algorithm?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: