Question: Let S be a sequence containing pairs (k, e) where e is an element and k is its key. There is a simple algorithm called
Let S be a sequence containing pairs (k, e) where e is an element and k is its key. There is a simple algorithm called count-sort that will construct a new sorted sequence from S provided that all the keys in S are different from each other. For each key k, count-sort scans S to count how many keys are less than k. If c is the count for k then (k, e) should have rank c in the sorted sequence.
(a) Give the pseudocode for count-sort as it is described above.
(b) Determine the number of comparisons made by count-sort. What is its running time, provide proper justification?
(c) As written, count-sort only works if all of the keys have different values. Explain how to modify count-sort to work if multiple keys have the same value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
