Question: Counting sort is a sorting technique that can be applied to a list holding integers from a certain range. Suppose that you are given a

Counting sort is a sorting technique that can be applied to a list holding integers from a certain range. Suppose that you are given a list of 10 integers and those integers are from the range 0-9. Instead of sorting those numbers directly, you count the frequency of each number and create a frequency list. Then you should use the frequency list to print the numbers in ascending order.

Input list: {1, 4, 1, 2, 7, 5, 2, 3, 9, 8}

Frequency list: {0, 2, 2, 1, 1, 1, 0, 1, 1, 1}

Then looking at the frequencies in frequency list, you should print the numbers in the original list in ascending order.

Two 1s: Print 1 1

Two 2s: Print 2 2

One 3: Print 3

One 4: Print 4

1 1 2 2 3 4

It should be a python code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!