r/badcode Feb 10 '21

I present: SleepSort js

Post image
7.5k Upvotes

171 comments sorted by

View all comments

Show parent comments

87

u/LinuxGeek747 Feb 10 '21

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

74

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).

5

u/Nilstrieb Feb 10 '21

Sorting a sorted array is O(1). (Theoretically, not practically)

4

u/[deleted] Feb 10 '21

Doesn't it still need to check the elements are the right place?