Are there any functions such as f(n) and g(n) that both;
f(n) != O(g(n)) and
g(n) != O(f(n)).
Are there any functions that fulfills the requir
f(n)=n and g(n)=n^(1 + sin(x)).
f(n) is not O(g(n)) and g(n) is not O(f(n)).
Refer http://c2.com/cgi/wiki?BigOh
Consider:
f(n) = 0 if n is odd, else n*n
g(n) = n
Then for odd values g(n)
is more than a constant factor bigger than f(n)
(and so g(n)
is not O(f(n))
, while for even values f(n)
is more than a constant factor bigger than g(n)
(and so f(n)
is not O(g(n))
).
Observe that f(n)
does not have a limit at infinity as n
approaches infinity, so in some sense this is a cheap example. But you could fix that by replacing 0, n, n*n
with n, n*n, n*n*n
.
I think if two non-negative functions have the property that f(n)/g(n)
has a (perhaps infinite) limit as n
approaches infinity, then it follows that one of them is big-O the other one. If the limit is 0 then f(n)
is O(g(n))
, if the limit is finite then each is big-O the other, and if the limit is infinite then g(n)
is O(f(n))
. But I'm too lazy to confirm by writing a proof.