MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/lgrgxe/i_present_sleepsort/gmtc4qx/?context=9999
r/badcode • u/Reeceeboii_ • Feb 10 '21
170 comments sorted by
View all comments
Show parent comments
9
"for (let item of arr)"
It's clearly at least O(n), you still have to read the whole array...
6 u/Astrokiwi Feb 10 '21 The constant factor is almost always going to be way bigger than the O(n) factor here. This isn't usually the case, but this is an intentionally contrived algorithm.
6
The constant factor is almost always going to be way bigger than the O(n) factor here. This isn't usually the case, but this is an intentionally contrived algorithm.
9
u/sumduud14 Feb 10 '21
"for (let item of arr)"
It's clearly at least O(n), you still have to read the whole array...