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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started