The value of sine function varies from -1 to 1. For sin = -1 or any other negative value, I becomes false. For sin = 1 or any other negative value, II becomes false

The Gateway to Computer Science Excellence

+45 votes

Let $f(n) = n$ and $g(n) = n^{(1 + \sin \: n)}$, where $n$ is a positive integer. Which of the following statements is/are correct?

- $f(n) = O(g(n))$
- $f(n) = \Omega(g(n))$

- Only I
- Only II
- Both I and II
- Neither I nor II

+16

0

I want to ask what is the use of the sentence "where n is a positive number".

My doubt is if n is a positive integer, then sin n can take the only value as 1.So, the function g(n)= O(n^2).

Please correct me.

My doubt is if n is a positive integer, then sin n can take the only value as 1.So, the function g(n)= O(n^2).

Please correct me.

+61 votes

Best answer

+16

Here g(n) is not n. It is $n^{1 + \sin n}$. So, D is correct. The complexity must be satisfied by **ALL** values of the function for large $n$.

+10

This example is given in CLRS 3rd Ed. PN 52. The book clearly says (and explains) that these two functions are not comparable asymptotically. Those still in doubt can refer the book to understand.

0

Since the value of sin(n) will always range from −1 to +1, hence g(n) can take values 1,n,n^{2} .

Hence, if g(n)=1, Statement I is incorrect,But at same time statement 2 is correct.

And, if g(n)=n^{2}, then Statement II is incorrect,and here also statement 1 is correct.

So option c or d,please explain.

+8 votes

actually sinn oscillates between -1 and 1.

So, g(n) has a range of values between 1 and n^2 i.e. g(n) = [1, n^2].

But we can't really compare f(n) and g(n) for large values of n.

So, (D) is correct without a shadow of doubt.

So, g(n) has a range of values between 1 and n^2 i.e. g(n) = [1, n^2].

But we can't really compare f(n) and g(n) for large values of n.

So, (D) is correct without a shadow of doubt.

+6 votes

n | f(n) | g(n) |
---|---|---|

90 | (90)^2 | 90 |

180 | 180 | 180 |

270 | 1 | 270 |

360 | 360 | 360 |

Here we can put different values of n ranging from 90 ,180 ,270 and 360 sometimes value of f(n) increases and sometimes g(n) ,so we cant say which one is greater or lesser.

Sine curve graph

OPTION D IS CORRECT

+4 votes

Answer is D.

Take different values for sinn -0,90,180,270,360 . You will find out that for 0,90 f(n)>g(n) and hence f(n)=omega(g(n)) and at 180,270 g(n) is greater therefor f(n) < g(n) i.e f(n)=Big-oh(g(n)) .therefore nothing is possible

Take different values for sinn -0,90,180,270,360 . You will find out that for 0,90 f(n)>g(n) and hence f(n)=omega(g(n)) and at 180,270 g(n) is greater therefor f(n) < g(n) i.e f(n)=Big-oh(g(n)) .therefore nothing is possible

0 votes

$sin(n)$ ranges from $-1$ to $1$ (So does $cos(n)$)

$f(n)=n$

$g(n)=n^{0 \ to \ 2}$

These are incomparable functions.

For a function to be $O$ of some other function, there must exist a constant $n_0$ after which the function can act as an upper bound of the other function.

Same concept can be extended to $\Theta \ or \ \Omega$

For any given $n$, $g(n)$ can be as large as $n^2$, or as small as $n^0=1$, or somewhere in between.

$g(n)$ can't bound $f(n)$

So, **Option D**

52,375 questions

60,586 answers

202,006 comments

95,409 users