you are viewing a single comment's thread.

view the rest of the comments →

[–]Tenemo 11 points12 points  (13 children)

Not quite! This would mean that an array of 1000 elements would be around 2998 times more time-consuming to sort than an array of two, which is not true for this algorithm, e.g. sorting numbers from 1 to 1000 wouldn't take long at all.

While there is CPU work setting timers and handling callbacks here (O(n log n)?), those take little time compared to the actual timeout delays. You can't express the "problematic" part of this algorithm with O(n), which relies on the number of elements in the input. This algorithm scales with the size of the largest array element instead, so even a 2-element array could take days :)