3 ms·
You could get arbitrarily large improvements by starting with even worse code ;)
by m4r35n357 6y ago
You could get arbitrarily large improvements by starting with even worse code ;)
- andi999 6y agoExactly. I like the enthusiasm of the author; but the self-congratulatory attitude doesnt go down very well if you should actually be ashamed of the first version. I mean it is only a few inches from:"you know in the old days we had to flip through the telephone directory from front to end to find a name. But you know what: it is actually a sorted list, so we applied a binary search algorithm and are 14000x faster. Tl;dr CS for the win"
- theamk 6y agoYou'd be surprised how often "flip through the telephone directory" thing comes out in the real projects. Sometimes it is one of those "we did a quick hack and then forgot about it as data sizes grew", sometimes one just forgot about the complexity, and occasionally there are people who don't understand the problem at all.
- andi999 6y agoI agree, and I also think this should be the first solution since it is obviously correct so you can test your faster algo later against this (at least in the post the invariants of the dataset are not spelled out exactly, and we know premature optimization..). But I do not think you should expect a trophy when later fixing it (when profiling shows it is a problem).