Using the data structures, create as class that performs a CountingSort algorithm.

The class you make should be a subclass of the class SortRoutine and be added into the SortDriver.

As explained, CountingSort builds a frequency table as part of its sorting logic. A frequency table counts up how many times a certain value occurred in the dataset being sorted. For example, consider the following list of numbers to be sorted: 1, 4, 7, 12, 15, 2, 2, 3, 7, 8, 12

A frequency table for this set of numbers would look like this: See image.

Once you have the frequencies, the sorted result is produced by outputting the correct number of values in order. In this case, that would be one 1, two 2s, one 3, one 4, two 7s, one 8, two 12s and one 15.

Here are the steps CountingSort needs to perform:

  • find the largest and smallest value in the dataset. This range of values determines how large your frequency array needs to be.
  • allocate a frequency array with the size of (largest-smallest + 1)
  • for each element in the frequency array, calculate its frequency in the dataset
  • starting with the smallest element, overwrite the dataset with the number of items shown in the frequency table
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.