7 ms·
> there appears to be considerable time worrying about the technicalities of the scheduler […] whether this really implies linear time bound. IMHO these are not
by sorbits 12y ago
> there appears to be considerable time worrying about the technicalities of the scheduler […] whether this really implies linear time bound. IMHO these are not worth worrying about
But it is not linear time, we shouldn’t let the existence of other algorithms make us confused about proper analysis of this one.
The call to `sleep(n)` is not a trivial operation, it inserts our task into a priority queue, so we are piggybacking on the OS’ support for sorting tasks based on when they need to be woken up, and thus hide the actual complexity behind the call to `sleep` (which we call `n` times, so if it’s `lg(n)` then the time complexity of the entire algorithm is `O(n lg n)`).
- bane 12y agoIt's also a good example of why O() isn't the entire story when it comes to how long an algorithm takes to run.