Advertisement

Is O(0) equal to O(1) ?

Started by July 10, 2015 08:29 AM
35 comments, last by cowsarenotevil 9 years, 2 months ago
Also, to add to what everyone else has been saying, if you want a mathematical basis for why O(1)!=O(0),its because

O(A(x)) = O(B(x)) iff |A|/|B| <= some positive real constant c for x->inf

So it's true that O(2)=O(1), and that O(1)=O(2). However, by definition, since 0/1 is not positive, and 0/1 < 1 forall x, O(0)=O(1) but O(1)!=O(0) which is indeed strange but makes sense if you think about it in terms of maximum bounds.

Now for the bonus question: can you name any nonconstant functions A and B, just from the definition above, where O(A)=O(B) but O(B)!=O(A)? :D

EDIT: I was an idiot 0 < all positive reals :P

I'm sorry about any spelling or grammar mistakes or any undue brevity, as I'm most likely typing on my phone

"Hell, there's more evidence that we are just living in a frequency wave that flows in harmonic balance creating the universe and all its existence." ~ GDchat

Same formal approach as samoth but with the product rule:

Product rule f € O(g), h € O(i) => f*h € O(g*i)
Lets assume f is O(0) and h is O(1).
Furthermore, lets define j € O(n).

f = h => f * j € O(x), h * j € O(y), x = y
(simply speaking: if f is equal to h, then big-O of product of f with an arbitraty function j is equal to big-O of product of h with same arbitraty function j)

Lets check:

f * j = O(0 * n) = O(0) | x = 0
h * j = O(1 * n) = O(n) | y = n

x != y, therefore f != h
So... O(0) != O(1)

Thats a typical theoretical (university) question - practically speaking, O(0) makes no sense. They just wanna make sure you understood the formal definitions or rather have learnt them by hard and know how to juggle with them to find solutions..
Advertisement

I would consider O(0) to mean no time taken at all.

Therefore the only way you're getting that is with delorian and a flux capacitor...

I would consider O(0) to mean no time taken at all.

Therefore the only way you're getting that is with delorian and a flux capacitor...

Is it maybe useful things that are solved at compile time?

Like if you replace a bit of runtime logic with some template metaprogramming solution, then you've switched from O(1) to O(0)?

O(1) is the set of functions that are eventually bounded by a (constant) positive real, while O(0) is the set of functions that are eventually zero. Note the function must be eventually exactly zero, it can't just tend to zero; the inverse function is not in O(0), for instance. As usual in asymptotics, that a function is in O(0) says absolutely nothing about the magnitude of the function at any given point, nor the complexity of an algorithm for any given instance of a problem. It just says that the function becomes zero for sufficiently large inputs, or that for inputs beyond some indeterminately large bound an algorithm will take exactly zero time. But programmers love to abuse big-O notation to mean whatever they feel it should mean on any particular day, so I guess it doesn't really matter rolleyes.gif

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

On the other hand, if an O(0) function that depends on a variable x takes non-zero time for some x, it would need to do some computation involving x (at least for those values). That would be O(1) at best, and I cant see a way it could do that check only for those values smaller than some number N. So it seems, for functions that are O(0) they always take no time.

openwar - the real-time tactical war-game platform

Advertisement

On the other hand, if an O(0) function that depends on a variable x takes non-zero time for some x, it would need to do some computation involving x (at least for those values). That would be O(1) at best, and I cant see a way it could do that check only for those values smaller than some number N. So it seems, for functions that are O(0) they always take no time.

Once again that depends on what you mean by a O(0) function. A function doesn't compute anything, it's an abstract mapping from one set to another that doesn't have any innate complexity. Typically we describe an algorithm's time complexity by a function that assumes values corresponding to the "time complexity" of the algorithm on any given input, where "time complexity" is a nebulous concept often represented by "steps" taken by some abstract computational device which is assumed to be roughly equivalent to the physical device on which the algorithm is supposed to be implemented, which allows you to perform quantitative measurements of execution time (or memory usage or any other relevant quantity) of varying quality depending on the accuracy of your abstract machine relative to its physical realization.

One could argue that in practice any algorithm implemented as, say, a function in some programming language, must take at least one unit of time to return (possibly nothing) but that need not be the case if the function call is elided by the compiler, a static analyzer or the runtime. You could retort to that it doesn't count if it's done at compile-time or even outside the function, or that metaprogramming is cheating and has time complexity zero, blah blah blah, blah blah blah, and at this point you are pretty far from the original mathematical definition of O(0).

Without a rigorous computational model (what it means for an algorithm or a piece of code to "compute" or "take time") the whole discussion is moot and saying that something "has time complexity O(0)" is handwavy and/or meaningless, whereas we can rigorously say that a function (in the mathematical sense) is or is not in O(0).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Everything takes some time. Therefore even a NOP machine code instruction isn't O(0) as time is taken with its execution even if the net result is nothing.

Nothing in the universe completes instantly so therefore O(0) shouldn't technically be possible.

Even reading a value defined already at compile time has an amount of time taken to execute, as there is always the fetch-execute cycle to worry about...

Maybe this could be called ?(0):

ppxze.jpg

However, since a cost cannot be negative and there are not real numbers minor then 0, it is also ?(0).

Therefore, that's an example of ?(0).

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/


"Is O(0) equal to O(1)?".

This question needs proper definition of "equal" termine that's supposed to relate those functions in the statement.

If this is in the pattern of mathematics, O(1) encapsulates many functions, such as 68/x for example, while O(0) will encapsulate only functions whose all values behind some functional value towards infinity equals 0. So no, they are different bigO functions - should not be equal.

This topic is closed to new replies.

Advertisement