3 ms·
I believe that the author is referring to the case when the array to be sorted contains only duplicates of a small number of items, where a perfect hash functio
by mfukar 16y ago
I believe that the author is referring to the case when the array to be sorted contains only duplicates of a small number of items, where a perfect hash function can speed up insertion; this turns cycle sort's time complexity into Θ(n+k), with k being the number of hashes. In such a case, k is not negligible compared to n, so I wouldn't feel comfortable saying cycle sort is O(n), as he does.
In the general case, cycle sort is Θ(n^2) with a total space complexity of Θ(n).
edit:typos.
- kingkilr 16y agoThis doesn't sound remotely right. If n is the number of elements, k is the number of distinct elements, and its O(n + k) as the author describes, k is trivially bounded by n (you can't have more distinct elements than you do elements). Resulting in O(n) complexity, how did you get O(n^2)?