Counting Sort

Facebooktwitterredditpinterestlinkedinmailby feather

Counting Sort

Counting sort is a sorting algorithm that is used to sort the elements of the array within a specific range. It counts the same element number of the array, and stores these same elements in the auxiliary array. It was developed by Harold H. Seward in 1954.

Complexity table of counting sort

Complexity Best case Average case Worst case
Time Ω (n + k) Θ (n + k) O (n + k)
Space     O S(nk)

Where n is the number of the element, and k is the range of the input.

Algorithm of counting sort

Example 1: Suppose we have the following array, which we have to sort.

5 5 4 1 8 2 2 3

Counting sort program in C language:

Facebooktwitterredditpinterestlinkedinmailby feather