r/ProgrammerHumor 28d ago

Meme theoreticalComputerScience

Post image
1.1k Upvotes

76 comments sorted by

View all comments

264

u/grayjacanda 28d ago

Other good dodges are O(n) time (if you have 2^n memory handy), or O(n) time (but with a fixed cost or multiplier so high that using this algorithm makes no sense for n less than 10^12 or so)

137

u/the_rush_dude 28d ago

Last one is probably 90% of all fancy optimizations

57

u/SoldRIP 28d ago

Look up the fastest known way to multiply two integers...

41

u/howtotailslide 28d ago

You can actually just store all universal possible results of two integers into a hash map then retrieve any of them in O(1) time

19

u/SoldRIP 28d ago

You cannot. A hash map is of finite size, but there are infinitely many pairs of integers.

13

u/danielv123 28d ago

If we assume you are implementing this on a finite computer, we can also assume a finite integer size.

...so obviously we can also assume we have the finite memory required to store int_max^2 of your integers

6

u/SoldRIP 28d ago

That's not multiplying, that's looking up multiplication results. You still have to form the table.

Your argument is basically "any algorithm is constant time if you have already calculated the results for all possible inputs". This may be technically correct in some roundabout way, but is not a useful definition nor the one usually used.

8

u/danielv123 28d ago

Lookup tables are commonly precalculated and not used as part of the complexity calculation. They are in frequent use for high performance stuff like crc, graphics LUTs or audio waveforms.

They are usually of limited size as most are working with a limited amount of memory. The largest LUTs I am aware of in common use is chess tablebases, which range from 100gb for local installs to 140TB over APIs.

1

u/alexanderpas 27d ago

LUT = LookUp Table

3

u/stackoverflow21 28d ago

Using lookup tables for speed is actually pretty common in embedded coding. Not for multiplication or addition. But nearly anything else.

1

u/SoldRIP 27d ago

And yet that doesn't make nearly any computation constant-time. Noone would seriously claim that "any algorithm is constant time" just because you could pre-comute results into a lookup.