Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The "Split the array into subarrays of length 5, now sorting all of the arrays is O(n) instead of O(n log n)" feels like cheating to me


O(n log 5) is O(n). There's no cheating, sorting small arrays in a list is a completely different problem from sorting a large array.


They're not sorting all the arrays?

Later

(i was going to delete this comment, but for posterity, i misread --- sorting the lists, not the contents of the list, sure)


It would only be cheating if you could merge the arrays in O(1), which you can't.


ahh this is the insight I was missing, thank you!


It’s unambiguously O(n), there’s no lg n anywhere to be seen. It may be O(n) with a bit larger constant factor, but the whole point of big-O analysis is that those don’t matter.


Actually lots of algorithms "feel" like cheating until you understand what you were not looking at (fast matrix multiplication, fast fourier transforms...).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: