What is the maximum number of comparisons needed to sort 6 items using radix sort, if each number is a 3-digit decimal number?
- (A)
120
- (B)
180
- (C)
210
- (D)
360
What is the maximum number of comparisons needed to sort 6 items using radix sort, if each number is a 3-digit decimal number?
120
180
210
360
ANSWER
The maximum number of comparisons is , so the answer is (B).
Official answer: BSource: ISRO's revised and final answer key of 16 February 2024
Radix sort (least significant digit first) does one pass per digit position. A 3-digit decimal number has positions, so there are passes.
In each pass, an item is placed in one of the digit buckets (0 to 9). In the worst case its digit is checked against each of the 10 possible digit values, which costs comparisons per item.
One pass over items therefore costs at most comparisons.
Over all passes the maximum is .
This agrees with the cost model in its usual form, where the work per pass grows with the number of items times the number of possible digit values.
Check against the options: and are not whole multiples of , and would need buckets, which a decimal digit does not have. Only fits.
KEY IDEA
Radix sort makes one pass per digit, and each pass handles every item against the possible digit values, so the count is with , , .
WATCH OUT FOR
Counting only operations, or using or buckets, instead of multiplying passes, items and the 10 possible decimal digit values.
From the ISRO CS 2023 paper. Every question of this paper · The full paper (PDF, ISRO) · All 3 ISRO Sorting & hashing questions, with notes