Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
546 views24 pages

Counting Sort

Counting sort is a sorting algorithm that is not comparison-based. It works by counting the number of objects that have each distinct key value, and using arithmetic on those counts to determine the positions of each key value in the output sequence. It has a worst-case running time of O(n+k) where n is the number of elements and k is the range of possible key values. Counting sort is used when the input consists of integers in a small range.

Uploaded by

AD Writes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
546 views24 pages

Counting Sort

Counting sort is a sorting algorithm that is not comparison-based. It works by counting the number of objects that have each distinct key value, and using arithmetic on those counts to determine the positions of each key value in the output sequence. It has a worst-case running time of O(n+k) where n is the number of elements and k is the range of possible key values. Counting sort is used when the input consists of integers in a small range.

Uploaded by

AD Writes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

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

You might also like