September 2019
Intermediate to advanced
816 pages
18h 47m
English
The counting sort flow starts by calculating the minimum and the maximum element in the array. Based on the computed minimum and maximum, the algorithm defines a new array that will be used to count the unsorted elements by using the element as the index. Furthermore, this new array is modified in such a way that each element at each index stores the sum of previous counts. Finally, the sorted array is obtained from this new array.
The time complexity cases are as follows: best case O(n + k), average case O(n + k), worst case O(n + k)
The space complexity case is as follows: worst case O(k)
Let's consider a quick example. The initial array ...