开发者

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

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 onl开发者_JS百科y 'correct' way to express it O(∞)?


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.)


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜