How many comparisons are needed in the worst case, if we need to sort 7 numbers, each of 4 digits (sorted by Radix) Possible options: 40,38,47,280.
My solution: I took 10 buckets (0 to 9) (linked list). Then for each number for the ith digit, I put it in a bucket corresponding to its digit value. Then I gathered these numbers into an array back. This process is repeated for all digits, and thus my original array is sorted. Total number of comparisons = 10 * 4 = 40 (10, because I repeated all the buckets to find the corresponding bucket).
Now the problem is the book of Timothy J. Williams, which he did not give comparisons = no numbers * no numbers * no buckets = 4 * 7 * 10 = 280. I can not understand. Can someone explain how this happened.
source share