5 ms·
* Don't get too hung up on computational complexity. A lot of times O(n^2) is gonna be perfectly fine. Write it the simple and easy to maintain way first, and
by Turing_Machine 5y ago
* Don't get too hung up on computational complexity.
A lot of times O(n^2) is gonna be perfectly fine. Write it the simple and easy to maintain way first, and only worry about fancy optimizations if it's too slow.
- chadcmulligan 5y agoAnd if it is too slow a hash table or two will probably fix it.
- BobbyJo 5y agoOptimize for humans first and computers second. Computers can read the crappiest, most spaghettified code on the planet as long as it is syntacticly and functionality correct. Humans cannot, and their time costs several orders of magnitude more.
- bluGill 5y agoin these days of modern CPUS with cache and branch prediction, O(n^2) often beats O(logn) because your data is tiny compared to the cost of all those cache misses and branch misses the seemingly faster algorithm creates. This doesn't apply when you data is large, but then you need parallel algorithms, and not in memory data (or just punt all your data to the sql server)
- AnimalMuppet 5y agoYeah. n = 3 more often than you expect. n <= 12 far more often than you expect. If you don't work at a FAANG, don't automatically assume that your data and algorithm need to squeeze the last O(logn) possible out of the algorithm.