Counting sort worst, best and average time complexity is O(n+k)
, where n is number of elements to sort. What is k exactly? I see different definitions: maximum element, difference between max element and min element, and so on.
- Given array
arr1 [1, 3, 5, 9, 12, 7 ]
andarr2 [1,2,3,2,1,2,4,1,3,2]
what isk
forarr1
andarr2
? - Is it true that it is stupid to sort
arr1
with counting sort becausen < k
(element values are from a range which is wider than number of elements to sort?