Linear time Sorting
Counting Sort
Use countng sort in a case, if all the intger
numbers lie in certain range; and that range is
should be known and small
It is not comparison based sorting, since we are not
comparing elements with each other.
It can be verified that the sorting is stable, if there are two
occurrences of an element in the input array, then after
sorting, the relative order of these two elements remain
unchanged.
Application: Counting sort is used as a sub-routing in other
sorting algorithms (Radix Sort)
It is used when there are few unique elements in an array.
Counting sort takes O(n+k) time in the worst case, where n
is number of elements and all the elements are in the range
1 to k (both inclusive).
In counting sort, the input to be sorted is assumed to be
more simply a sequence of integers itself,
Counting Sort
Counting sort
Counting Sort
Counting S Counting sort ort
Counting sort
Repeat the same
process up to
A[11]
Counting sort
C set to rank each number of A
Counting sort
Counting sort
Counting sort
Counting sort
Counting sort
Counting sort
Counting sort
Counting sort
Counting sort
Counting sort
Counting sort
Counting sort