@@ -6,9 +6,15 @@ Counting sort is a non-comparison-based sorting algorithm and isn't bounded by t
66of most sorting algorithms. <br >
77It first obtains the frequency map of all elements (i.e. counting the occurrence of every element), then
88computes the prefix sum for the map. This prefix map tells us which position an element should be inserted.
9- It is updated after each insertion to reflection the new position to insert the next time the same element is
9+ It is updated after each insertion to reflect the new position to insert the next time the same element is
1010encountered. <br >
1111
12+ ![ counting sort img] ( ../../../../../../docs/assets/images/CountingSort.png )
13+
14+ Image Source: https://www.oreilly.com/library/view/mastering-algorithms-with/1565924533/ch12s13.html
15+
16+ _ To align with the naming convention of our implementation, data => arr, counts => freq, temp => sorted._
17+
1218### Implementation Invariant
1319
1420** At the end of the ith iteration, the ith element (of the original array) from the back will be placed in
@@ -35,5 +41,7 @@ Counting sort is NOT AN IN-PLACE algorithm. For one, it requires additional spac
3541
3642## Notes
3743
38- 1 . Counting sort (stable version) is often used as a sub-routine for radix sort.
39- 2 . Supplementary: Here is a [ video] ( https://www.youtube.com/watch?v=OKd534EWcdk ) if you are still having troubles.
44+ 1 . Our counting sort implementation works only on non-negative integers. However, to adapt it to work for arrays with
45+ negative integers, we can add an offset of +m, where m is the smallest integer in the array.
46+ 2 . Counting sort (stable version) is often used as a sub-routine for radix sort.
47+ 3 . Supplementary: Here is a [ video] ( https://www.youtube.com/watch?v=OKd534EWcdk ) if you are still having troubles.
0 commit comments