Antheus, however, is arguing that, for various reasons, there is also an O(n) term in practice (note that this really doesn't matter, since O(n) will always be less than O(b) anyway). I'm simply pointing out that, in the shell script posted, the real work is being done by the Unix scheduler, and that not only is it not being run in parallel, but that it is actually ultimately a comparison sort, and so bounded by O(n log n).
Whether we treat this as comparison sort comes down to one thing - is strict ordering of Sleep() timings preserved or not.
My claim is that it's not, since we're working with finite set of time values (integers in original example, but even floats have same problem). [1,1,1,1] - what order will they be printed?
As such, many input values will result in same discrete delay, hence "a bucket'.
If however we require that sort be stable, then it becomes a full comparison sort and logn bound.
The stability argument here is a difficult one, especially after looking at real world schedulers, which, on non-real-time OS or on multiple threads are not deterministic, hence the argument for a comparison sort doesn't hold. We end up with unstable sort. Scheduler behavior therefore becomes a property of algorithm itself. A scheduler which doesn't preserve strict order can be O(1). Even order-preserving scheduler can be O(1) at expense of memory. it's impractical as general purpose algorithm, but looks something like this:
std::list<Process*> next_to_execute[MAX]; // next_to_execute = list of processes to execute at time i
void sleep(int n) {
next_to_execute[now + n].append(this);
}
void main() {
while (running) {
execute_all(next_to_execute[now]);
now++;
}
}
To demonstrate this, original example could be modified to store tuples of (value,index). Under typical scheduler, values belonging to same bucket would print in arbitrary order. At very least, most schedulers do not guarantee order of execution, especially on multiple threads, where such automatic synchronization would serialize entire code.
For me, stable comparison sort is a special case of the problem, one which most schedulers will not be able to achieve due to non-deterministic nature of threads. So might as well go for unstable non-comparison sort.
doesn't have much to do with the asymptotic complexity.[/quote]
Bucket sort is O(n). If original example can be shown to be equivalent, then it has same complexity.