Post

*dull mode on* No, it doesn't. As stated in comments above the time complexity of the sleepsort depends not on the quantity of the elements in input data, but on elements' values. Taking the O for the sleep(n) itself as O(n) we get the n=MAXn(Vi) for the best case (enough CPUs) and ...

...n=SUMn(Vi) for the worst case - on a single core. It actually makes big-O notation useless here, since it cannot show how the algorithm scales on elements quantity. Actually, it's impossible to find any asymptotic function for such case, since the input data values unknown

0 reposts1 like

PS. It's better keep in mind the "time" in "big-O time complexity" isn't about a time in seconds or any time units, but about the operations/steps quantity. And not the absolute quantity but a function, which would asymptotically close to the quantity. It's about scalability, not the absolute time

In addition, I would not consider sleepsort as a sorting algorithm at all, since it's defined only for natural numbers. If you get an abstract data element with only comparator defined, you will have to associate an ordinal number to each element first, what implies ... sorting them.

For sure. But imagine we had a hashing function without many collisions to map each element to a time slice. Of course one could directly sort using said function, but wouldn't it be interesting to dispatch multiple threads and have each schedule an insertion? We could cook this a little more!

Imagine this oddly manufactured use case: You get multiple unordered streams of elements, each element with an expiration date. Imagine you can check the current time at any moment, and only those elements that haven't expired at insertion get to be considered. 1/2