RedditPP Mascot

RedditPP

r/algorithms • … • u/lazyubertoad

Any usage of the number n is O(log(n))

Yes, if you use n, you need log(n) time. I think it's kind of obvious from the mathematical point of view. You need log(n) digits and nothing could be done about that.

And you know what - the fact is, well, just ignored in all that asymptotic complexity analysis. Maybe it's just me who never saw this stated explicitly? That one must generally ignore the fact, as we have limited memory and our n cannot really be more than memory size, hence the pointer sizes and our fixed size integers. Wiki states that "Determining if an integer (represented in binary) is even or odd" is O(1)! Bullshit? And that O(1) in hashes is actually a well hidden log(n) from this point of view. And probably nothing is REALLY O(1).

I'm not some freak that wants to revise all the O(n) analysis based on this, but... Well, I was really confused for quite a long time in the beginning of the study and maybe it's not just me. And as it is really log(n) maybe in some cases it actually matters, as there are algorithms that use big integers. From one point of view it shows us that log(n) is small and actually const limited in (most of the) practice. But it surely is not ignored, fex comparison sort is n*log(n), not n (and yes, radix sort is the way you hide log(n) in number).

Maybe the fact needs some more attention or something?

— 0