Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you make the assumption that there is an upper bound on the maximum time a read can take (e.g. reading from disk), reading from memory becomes an O(1) operation regardless of cache misses.


If you make that assumption, sure. If instead you assume that you live in a universe where information can't propogate faster than the speed of light (true), storage takes up space (true), and memory is arranged on an plane (generally true in practice), then you get back to sqrt(n) access times. If some day we move to totally 3D computers we can get that down to cube root of n.


Anthropic O(1) argument: An algorithm will either finish before all humanity dies, or it won't. If it does, it's bounded from above by a constant. If it doesn't, it's completely irrelevant to everyone. So for all practical purposes every algorithm is O(1).


By similar assumption, every terminating algorithm running on a real computer (having bounded memory) is O(1). This is technically true, but not useful.

Most people assume the average memory access will be reasonably fast (why we have a cache hierarchy in the first place). Sometimes the growth of it matters, sometimes it does not.

Algorithm complexity is not something to be memorized, but analyzed.


The assumption that the computer you are modeling has an infinite amount of memory finite number of caches is a useful assumption as it dramatically simplifies the analysis and still allows you to use big-O to somewhat accurately analyze the performance of a real computer.


You missed what I was illustrating by referencing bounded memory - every realized program has a finite (therefore constant-bounded) number of states. The point is that such analysis is not useful, because it "cheats" with an misleading implicit constant for the bound.

Similarly, if one is analyzing the performance of a general algorithm and assumes memory access is constant time, then that constant needs to be understood as the full access time of main memory (assuming that's what problems will always fit in).

One cannot casually make this assumption to get an O(n) complexity result, profile the program with a problem size that actually fits in cache, and then combine the two to extrapolate larger running time. They each have different baked-in assumptions.


Yes, that assumption can be used to make any operation O(1).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: