Hacker News new | past | comments | ask | show | jobs | submit login

The point was that you can often convert nested loops into two loops that are not nested. O(2n) conveys that, O(n) does not.



Actually O(2n) did not convey this for me at all, all it did for me was cause confusion. If this ("turn it into two not nested loops") was indeed intended, I'd suggest to spell it out, not abuse notation


> If this ("turn it into two not nested loops") was indeed intended, I'd suggest to spell it out, not abuse notation

O(2n) is not an abuse of notation. It's just as well defined as O(n). The fact that O(2n) is a subset of O(n) is a theorem, not part of the definition of the notation.


It's a subset, but also a superset.


Yes? But to replace O(2n) with O(n), you only need that it's a subset.


You have your point.


Interesting, I hear people spelling out constants all the time when using the O notation to put emphasis where they want. I guess that's not really as universal as I thought, but I still think it's a good way to express.


It can cause more confusion though, if say you write O(kn), but the oh-notation hides a factor k^3, then it would be better to just write O(n). Or write O_k(n) to signify a hidden dependency on k. Or best of all, just write out k^4 n without any ohs at all.




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

Search: