13

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(∞)?

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
Poul Walker
  • 131
  • 1
  • 3
  • 1
    Interesting. Never heard of O(\infty) – gd1 Apr 11 '11 at 20:52
  • 3
    [Bogosort](http://en.wikipedia.org/wiki/Bogosort) is this, according to Wiki. –  Apr 11 '11 at 20:53
  • 1
    @delnan: every operating system should be designed to run forever, and so should many GUIs. – Fred Foo Apr 11 '11 at 20:57
  • @larsman: What gives? I know that and never claimed otherwise. I was merely providing a link for Giacomo and potentially others that would like an example of `O(infinity)`. –  Apr 11 '11 at 21:02
  • 1
    @delnan: I wasn't pointing out a mistake. I was just giving examples of more useful programs :) – Fred Foo Apr 11 '11 at 21:03

4 Answers4

12

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

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • Your point is ofcourse valid, it's outside the definition in a way, but using o(infinity) as the runninng time of a non terminating program is just a, sometimes used, convention – Peter Apr 11 '11 at 21:27
  • 1
    @Peter: I've never seen it. I'd find it confusing and I believe I'm not the only one :) – Fred Foo Apr 11 '11 at 21:29
  • http://en.wikipedia.org/wiki/Bogosort, as pointed out, but aside I agree, I'm not a fan of it either. – Peter Apr 11 '11 at 21:32
  • @Peter: ah, I hadn't spotted the infobox. (Strange: in Prolog programming, bogosort is the name for the one-liner that sorts by walking through all permutations, `sort(Lst,Srt) :- permutation(Lst,Srt), sorted(Srt).`, which runs in O(n!).) – Fred Foo Apr 11 '11 at 21:34
  • Yes, but sorting by coincidence can of course be much worse than all permutations, never ending is the WCS, not the average. Same name for different things apparantly; interesting info though. – Peter Apr 11 '11 at 21:42
7

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.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 6
    An "algorithm that never terminates" is formally not an algorithm (no matter how useful it is). – Fred Foo Apr 11 '11 at 20:55
  • 1
    What about `strlen` in C when it's not given a NUL-terminated string, there is infinite memory and no zeros in that memory? Purely hypothetical, but does that count? –  Jun 26 '11 at 20:55
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.

Peter
  • 47,963
  • 46
  • 132
  • 181
0

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.

ikegami
  • 367,544
  • 15
  • 269
  • 518