O-notation, O(∞) = O(1)?

筅森魡賤 提交于 2019-12-09 02:49:44

问题


So a quick thought; Could one argue that O(∞) is actually O(1)?

  • I mean it isn't depend on input size?
  • So in some way its, constant, even though it infinity.

Or is the only 'correct' way to express it O(∞)?


回答1:


Infinity is not a number, or at least not a real number, so the expression is malformed. The correct way to express this is to simply state that a program doesn't terminate. Note: program, not algorithm, as an algorithm is guaranteed to terminate.

(If you wanted, you might be able to define big-O notation on transfinite numbers. I'm not sure if that would be of any use, though.)




回答2:


Your argument is not quite correct.

Big O notation disregards constant multiples; there's no difference between O(1) and O(42), or between O(log(n)) and O(3π log(n)) .

Standard convention is to not use any constant multiples.

However, O(∞) would mean an “algorithm” that never terminates, as opposed to O(1) which will terminate at some point.




回答3:


To answer the question :

O-notation, O(∞) = O(1)?

No

The main difference is that O(1) will end at some point, while O(∞) never ends.

They both don't include a variable, but have both different meanings :

O(1) (or O(121) or O(whatever but not infinity) : independendent of the functions arguments, but ending

O(∞) : independendent of the functions arguments, and non ending

As pointed out in another answer, infinity isn't really in the domain of the big-O notation, but the simple 'no' than remains of course, O(1) and O(∞) are not the same.




回答4:


Big-Oh is a measure of how something the resources required scales as N increases. O(5 hours) and O(5 seconds) are both O(1) since no extra resources are needed as N increases.



来源:https://stackoverflow.com/questions/5627390/o-notation-o%e2%88%9e-o1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!