in Algorithms edited by
16,187 views
39 votes
39 votes

Consider the following functions:

  • $f(n) = 2^n$
  • $g(n) = n!$
  • $h(n) = n^{\log n}$

Which of the following statements about the asymptotic behavior of $f(n)$, $g(n)$ and $h(n)$ is true?

  1. $f\left(n\right)=O\left(g\left(n\right)\right); g\left(n\right)=O\left(h\left(n\right)\right)$
  2. $f\left(n\right) = \Omega\left(g\left(n\right)\right); g(n) = O\left(h\left(n\right)\right)$
  3. $g\left(n\right) = O\left(f\left(n\right)\right); h\left(n\right)=O\left(f\left(n\right)\right)$
  4. $h\left(n\right)=O\left(f\left(n\right)\right); g\left(n\right) = \Omega\left(f\left(n\right)\right)$
in Algorithms edited by
16.2k views

4 Comments

$n! = O(n^{n})$

Now $2^{n}$    $n^{n}$    $n^{logn}$

take log  $\Rightarrow$   n     nlogn      lognlogn

it's clear that among these 3 nlogn has the highest growth rate, Now compare n & lognlogn

           n         lognlogn
            n=8 8 9
            n=16 16 16
            n=32 32 25

So, after n = 16 , lognlogn is overtaking n, that's why lognlogn > n 

So, $lognlogn<n<nlogn$  which implies only option D

7
7

take log both side and compare function

0
0

n! Factorial is always greater than exponential. And 2^n always > n^logn (Remember the sequence of what has higher growth rate than compared to others) 

Hence h(n)<f(n)<g(n)

So h(n)= Of(n) and f(n)=Og(n)

We can also write f(n)=Og(n) as g(n)=omega(f(n))

Hence option D is correct.

 

 

2
2

5 Answers

48 votes
48 votes
Best answer

$g(n) = n!$.

On expanding the factorial we get $g(n) = O(n^n)$ :$$\begin{align*} n^n &> n^{\log n} \\ n^n &> 2^n \end{align*}$$This condition is violated by options $A$, $B$ and $C$ by first statements of each. Hence, they cannot be said to be TRUE.

Second statement of option $D$ says that $g(n)$ is asymptotically biggest of all.

Answer is option (D).

edited by

4 Comments

I think in option A because of 2nd statement it is wrong. am i right?
0
0
0
0

amarVashishth

This condition is violated by options A, B and C by first statements of each.

 In option B and C this is correct. but for option A it is wrong.

 f(n) = O(g(n))  implies  $2^{n}=O(n!)$    first statement is correct.

g(n)=O(h(n)) implies   $n!=O(n^{logn})$  second statement is false.

1
1
30 votes
30 votes
  $f(n)$ $g(n)$ $h(n)$
$n = 2^{10}$ $2^{1024}$ $1024!$ ${2^{10}}^{10} = 2^{100}$
$n = 2^{11}$ $2^{2048}$ $2048!$ $2^{121}$
Increase $2^{1024}$ $1025 \times 1026 \times \dots \times 2048$ $2^{21}$

So, growth rate is highest for $g(n)$ and lowest for $h(n)$. Option D. 

by
23 votes
23 votes
Take log of all function with base 2

log(f(n)) = Log(2^n)  = n

log(g(n)) = Log(n!) = Log(n^n) // using sterling approximation = nlogn

Log(h(n)) = Log(n ^ logn) = log(n) * log(n).

It becomes clear now that h(n) < f(n) < g(n).

Looking at options D is only option which satisfy this constraints.

1 comment

In D, h(n) = O(f(n)), is this right?/
0
0
9 votes
9 votes

Answer is D.

1 < loglogn < logn < n< n< nlogn < c< nn < cc^< n! .

1 comment

1 < loglogn < logn < n< n< nlogn < c< nn < cc^< n!

isn't n! = O(n^n)?

4
4
Answer:

Related questions