3 ms·
> You don't need to run a program to determine that an O(n^2) approach will be slower than an O(log n) algorithm. That depends on N and on the constant factors
by inimino 9y ago
> You don't need to run a program to determine that an O(n^2) approach will be slower than an O(log n) algorithm.
That depends on N and on the constant factors. Which means testing still might surprise you.
More to the point, if the O(n^2) algorithm is simpler and leaves you more time for profiling and fixing actual performance issues after the code works, you may end up with faster code by doing the dumb thing.