I am asked to find two functions that are not big-oh of each other. Is it correct if I pick say $f(n)=2\sin (n)$ and $g(n)=1$? That way, $f$ will never always be greater than $g$.
-
You should pick functions that are positive (at least from a point on) And your general idea is OK, but you should make sure that $f(n) \ne O(g(n))$ and $g(n) \ne O(f(n))$, and you should presumably add proofs. – vonbrand Feb 14 '14 at 21:19
3 Answers
$\sin n \in O(1)$. Note the arbitrary constant in the definition of $O$.

- 3,667
- 15
- 18
Some people are picky about negative-valued functions. Here's one that will satisfy even picky people: $$ f(n) = n,\qquad g(n)=\begin{cases} n^2 &\text{if $n$ is even}\\ 1 & \text{if $n$ is odd} \end{cases} $$ There clearly isn't a constant $k$ for which $f(n)\le k\cdot g(n)$ eventually so $f$ isn't big-O of $g$ and in the same way we can see that $g$ isn't big-O of $f$.

- 14,826
- 5
- 42
- 54
The sine function oscillates between 1 and -1 up to a constant factor. So it would be correct to say that the function is $O(1)$ if the function is used to describe the runtime complexity of an algorithm, i.e. a complexity which oscillates as input size goes from $1,2,3$ to ... You could use $AbsoluteValue(sin(x))$ for the negative... Or $Sin(x)+1$...

- 11
- 2