Radix sort: LSD versus MSD versions

Geek picture Geek · Aug 13, 2012 · Viewed 22.1k times · Source

The book "Introduction to Algorithms" mentions about the LSD (Least Significant Digit) version of radix sort. However , as others have pointed out here in stackoverflow, a MSD (Most Significant Digit) version also exists. So I want to know the pros and cons of each of these. My guess is that the LSD version has some benefits over the MSD one but I am not sure. Hence the question.

Answer

Roman Dzhabarov picture Roman Dzhabarov · Aug 14, 2012

Taken from the link, might be useful: http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx (At the very bottom)

The biggest problem with LSD radix sort is that it starts at the digits that make the least difference. If we could start with the most significant digits, the first pass would go a long way toward sorting the entire range, and each pass after that would simply handle the details. The idea of MSD radix sorting is to divide all of the digits with an equal value into their own bucket, then do the same thing with all of the buckets until the array is sorted. Naturally, this suggests a recursive algorithm, but it also means that we can now sort variable length items and we don't have to touch all of the digits to get a sorted array. This makes MSD radix sort considerably faster and more useful.