3 ms·
I have seen plenty of developers create websites using a lot of O(n^2) code when O(n log n) was an option. Often its simple questions like should I sort this b
by onemoreact 15y ago
I have seen plenty of developers create websites using a lot of O(n^2) code when O(n log n) was an option. Often its simple questions like should I sort this before I do some manipulation and working though which is faster can literally take a few seconds of thought. That's not to say you need to always write optimized code, just avoid writing dumb code when you know it's going to be a problem ahead of time.
- wanorris 15y agoIf it's the same amount of work and readability is not sacrificed, consistently using O(n log n) is a good practice for that situation. If the result is more effort or less readable, then an understanding of what n is going to be like is probably worthwhile. For the love of all that's holy, please do not optimize access to a collection of days of the week that is accessed infrequently.