4 ms·
If you replace an n^2 algorithm with a log(n) lookup you get an exponential speed up. Although a hashmap lookup is usually O(1), which is even faster.
by csnweb 1y ago
If you replace an n^2 algorithm with a log(n) lookup you get an exponential speed up. Although a hashmap lookup is usually O(1), which is even faster.
- ryao 1y agoThat is not true unless n^C / e^n = log(n) where C is some constant, which it is not. The difference between log(n) and some polynomial is logarithmic, not exponential.
- csnweb 1y agoBut if you happen to have n=2^c, then an algorithm with logarithmic complexity only needs c time. Thats why this is usually referred to as exponential speedup in complexity theory, just like from O(2^n) to O(n). More concretely if the first algorithm needs 1024 seconds, the second one will need only 10 seconds in both cases, so I think it makes sense.
- ryao 1y agoN is a variable in what I posted, not a constant.
- wasabi991011 1y agoIt depends if you consider "speedup" to mean dividing the runtime or applying a function to the runtime. I.e. you are saying and f(n) speedup means T(n)/f(n), but others would say it means f(T(n)) or some variation of that.
- morepedantic 1y agoThe man, or llm, used the mathematically imprecise definition of exponential in a sentence with a big-O notation. I don't think he's going to be writing entire arguments formally.
- ndriscoll 1y agoThey're still using the map in a loop, so it'd be nlogn for a tree-based map or n for a hash map.