3 ms·
O(N^2) forgets that in most cases it's really more like K * O(N^2) + I and reducing the size of K can have dramatic impact because it tends to be more than 10,0
by Retric 18y ago
O(N^2) forgets that in most cases it's really more like K * O(N^2) + I and reducing the size of K can have dramatic impact because it tends to be more than 10,000 cycles. For a wide range of inputs a low latency N^2 can be faster than a high latency n * Log n because thrashing you cache is really bad.
The basic question you need to ask is how much are you spending on hardware / bandwidth vs coders and which is better to focus on.
- geebee 18y agoThat's really well put. In this case, I'd say you need programmers to reduce the O(N^2), and hardware to reduce the K. If you can reduce K by 50% for $5,000, then it makes almost no sense to use a programmer to reduce K. However, hardware will almost never save you from a programmer who gives you an O(N^2) instead of a log N solution. This happened at my last job (actually, worse). Management decided I would be an "Architect" and train an offshore team to write the code (hmm... seems kind of fishy). We were building a system that would hold an equation with millions of constraints and variables, and we needed to be able to look up a variable value by name. The code from the offshore team, no kidding, stored them in arrays. Unreal. I quit, for all kinds of reasons. (yes, yes, many offshore teams could have written this code very well - the problem was not offshore programmers per se, it was that mgmt wanted top talent for cheap and was outsourcing its core product, and you don't get something for nothing).