4 ms·
Exactly. What do you do when you have the right algorithm and it’s too slow (very typical for linear problems that require visiting each item).
by tightbookkeeper 2y ago
Exactly. What do you do when you have the right algorithm and it’s too slow (very typical for linear problems that require visiting each item).
- anyfoo 2y agoYou optimize the constant factors, e.g. the runtime of the inner loops. But this requires you to choose a sane algorithm in the first place. Some problems are much more complicated, where you have to take, for example, locality (cache hierarchy etc.) and concurrency considerations like lock contention into account. This may affect your choice of algorithm, but by the time you reach that, you've almost certainly thought about the algorithm a lock already.