menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Sorting Al...
source image

Prodevelopertutorial

3w

read

136

img
dot

Image Credit: Prodevelopertutorial

Sorting Algorithm 11: Counting Sort 

  • 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.

Read Full Article

like

8 Likes

For uninterrupted reading, download the app