Question: Part 3 : Counting sort Do the same thing as part 1 , but with the counting sort, as described here. The counting sort can
Part : Counting sort
Do the same thing as part but with the counting sort, as described here.
The counting sort can sort an array of integers that are known to be in a given range of
integers by using a second array count to count the number of occurrences of each integer
in the array.
As an example, let's say we have an array called scores containing the following ten integers
in the range between and inclusive:
In this case, the count array would have five elements, one for each possible value through
We initialize count to all zeros. We then make one pass through scores each time we
see a given value in scores, we increment the value in count When we are done,
count will tell us how many instances of the value we have in scores. In this example,
count would be:
because there are zeros, one, twos, threes, fours in scores.
Once you have this array count, it is straightforward to determine the sorted scores array:
and store it back into the original array.
Write a C function that implements the counting sort, assuming an array of integers that
are in the range to inclusive.
In big O notation, what is the expected efficiency? Why is counting sort impractical as a
general sorting algorithm?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
