-1

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

Glorfindel
  • 752
  • 1
  • 9
  • 20
user14677
  • 1
  • 1
  • 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 Answers3

2

$\sin n \in O(1)$. Note the arbitrary constant in the definition of $O$.

Karolis Juodelė
  • 3,667
  • 15
  • 18
1

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

Rick Decker
  • 14,826
  • 5
  • 42
  • 54
0

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

user14685
  • 11
  • 2