Big O with cosine?

2.1k Views Asked by At

Consider the functions $f(n) = n\cdot \max(0,\cos(\pi n))$, $g(n) = n$. What is the relation between these functions in big-$\mathcal O$ notation? Assume $n$ takes on only positive integer values. For the cosine, the angle is being expressed in radians.

How do I compare functions with cosine in them with regards to big $\mathcal O$? I think that $f(n)$ is $\mathcal O(g(n))$ because it is strictly less than or equal to $c\cdot n$ with $c = 1$. In addition, $f(n)$ is not $\Theta(g(n))$ because there is no positive constant $c$ where $g(n)$ is strictly less than or equal to $f(n)$. Is this intuition correct?

2

There are 2 best solutions below

0
On

Hint: Is there a simpler way to express $\cos(\pi n)$? Take a look at the values of $\cos(\pi n)$ for some values of $n$ ($n=1,2,3,4,5$). Can you find a pattern?

0
On

Note that $f(n) = \left\{\begin{array}{lr} 0: \quad 2\nmid n\\ n: \quad 2\mid n\end{array}\right.$