-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
  • 754
  • 1
  • 9
  • 20
user14677
  • 1
  • 1

3 Answers3

2

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

Karolis JuodelÄ—
  • 3,697
  • 16
  • 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
  • 15,016
  • 5
  • 43
  • 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
  • 21
  • 2