I still have no idea why radix sort preferred to Least Significant Digit first after reading introduct to algorithm.In my opinion,Most Significant Digit first should be the same as Least Significant Digit first,even better.Because the most Significant Digit first is heavier than the least,and it can reduce the sort times.Who can help to explain it ?
Consider an example population with the values
91, 19, 55, 54
If you first distribute by LSD (ahem), you get
91, 54, 55, 19
then by MSD;
19, 54, 55, 91
- good
Now instead distribute first by MSD:
19, 55, 54, 91
and then by LSD:
91, 54, 55, 19
- bad
Because Most Significant Digit first
not works if you don't do extra works in number inputs.
Try think about the number input set: 1 2 10
Now you use MSDF
in the below way(Not the Least Significant Digit first Way):
Tens bucket: 1 10
Twenties bucket: 2
since two ten bucket just has one item, just handle one ten bucket
Zero bucket: 1 10
so final order is 1 10 2
wrong!
if you do the extra works for put the all number in same length, it will works:
adjust input to same length 01 02 10
Zero ten bucket: 01 02
Tens bucket: 10
since Tens bucket just has one item, just handle Zero ten bucket
One bucket: 01
Two bucket: 02
so final order is 01 02 10
right!
91, 19, 55, 54
in MSDF
:all number is in the same length
Tens bucket: 19
Fifties bucket: 55 54
Nineties bucket: 91
since Tens bucket and Nineties bucket just has one item, just handle Fifties bucket
Four bucket: 54
Five bucket: 55
so final order is 19 54 55 91
right!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With