4 ms·
Let's say you have a lookup table and your algorithm looks up a value and returns it. O(n) space O(1) in time.
by ajuc 2y ago
Let's say you have a lookup table and your algorithm looks up a value and returns it. O(n) space O(1) in time.
- yxhuvud 2y agon is some value depending on the size of the input, so if you have a look up table that is O(n), then that memory needs to be initialized somehow. If you have a fixed size lookup table then it is O(1), even if it is big.
- ajuc 2y agoCompile time fill a lookup table. Run time read 1 value from it. I call it O(1) in time, O(n) in memory. You call it O(1) in both, right? Now move the compile time code to runtime. I call it O(n) in time and memory. What do you call it? If your say O(n) in time and memory - why is moving the code changing its complexity? If you say still O(1) - then everything is O(1), thus proving P=NP among other things :) Either way your interpretation isn't very useful.