Counting sort algorithm is a linear sort algorithm.
Steps for performing Counting Sort: Find the minimum and maximum value from the array. Create a second array from the minimum value to maximum value. Increment the second array whenever we find a number from the first array. Once all the numbers will be written, take the sum and place the elements in the respective positions.
Example: Consider an array and sort it using counting sort algorithm. The array is sorted in ascending order by counting the frequency of each element. The implementation of counting sort in C is provided.
Time complexity of counting sort is O(n+r), where n is the number of elements in the array and r is the range of the input.