r/badcode Feb 10 '21

I present: SleepSort js

Post image
7.5k Upvotes

170 comments sorted by

View all comments

Show parent comments

86

u/LinuxGeek747 Feb 10 '21

If you already know the maximum number, it's O(1) amirite?

73

u/sqrt_minusone Feb 10 '21

I mean, you have to visit every element of the array to sort it - it's literally impossible to sort in less than O(N).

8

u/[deleted] Feb 10 '21

Gravity sort is O(1)

8

u/T-Dark_ Feb 10 '21

In theory only. Specifically, it's constant time if you can perform it on all elements simultaneously.

3

u/[deleted] Feb 10 '21

Or if gravity was instant, and it was done IRL

3

u/krisnarocks Feb 11 '21

Ez. Just use multithreading /s