Counting sort is a sorting technique that works on keys within a specific range by counting the number of objects with each key value and using the counts to determine the positions of objects in the sorted output. It involves taking an input, counting the frequency of each unique key, modifying the counts to be cumulative, and then using the counts to place each object in the output sequence.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views5 pages
Counting Sort
Counting sort is a sorting technique that works on keys within a specific range by counting the number of objects with each key value and using the counts to determine the positions of objects in the sorted output. It involves taking an input, counting the frequency of each unique key, modifying the counts to be cumulative, and then using the counts to place each object in the output sequence.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5
WHAT IS COUNTING SORT?
Counting sort is a sorting technique based on keys
between a specific range. It works by counting the number of objects having distinct key values EXAMPLE: consider the data in the range 0 to 9. Input data: 1, 4, 1, 2, 7, 5, 2 EXAMPLE
1) Take a count array to store the count of each
unique object. Index: 0 1 2 3 4 5 6 7 8 9 Count: 0 2 2 0 1 1 0 1 0 0 2) Modify the count array such that each element at each index stores the sum of previous counts. Index: 0 1 2 3 4 5 6 7 8 9 Count: 0 2 4 4 5 6 6 7 7 7 The modified count array indicates the position of each object in the output sequence. 3) Output each object from the input sequence followed by decreasing its count by 1. Process the input data: 1, 4, 1, 2, 7, 5, 2. Position of 1 is 2. Put data 1 at index 2 in output. Decrease count by 1 to place next data 1 at an index 1 smaller than this index. NOW GO TO ANIMATION https://www.google.com.pk/url?url=https://w ww.cs.usfca.edu/~galles/visualization/Countin gSort.html&rct=j&q=&esrc=s&sa=U&ei=GGNb VJWvOoXlarP4gPAK&ved=0CDEQFjAF&usg=AF QjCNFz2Wgm0-MoNh3UpMslky1cZPiFuQ