recategorized by
26,297 views
71 71 votes

Consider the following two functions:

$g_1(n) = \begin{cases} n^3 \text{ for } 0 \leq n \leq 10,000 \\ n^2 \text{ for } n > 10,000 \end{cases}$

$g_2(n) = \begin{cases} n \text{ for } 0 \leq n \leq 100 \\ n^3 \text{ for } n > 100 \end{cases}$

Which of the following is true?

  1. $g_1(n) \text{ is } O(g_2(n))$

  2. $g_1(n) \text{ is } O(n^3)$

  3. $g_2(n) \text{ is } O(g_1(n))$

  4. $g_2(n) \text{ is } O(n)$

8 Answers

Best answer
99 99 votes
For asymptotic complexity, we assume sufficiently large $n$. So, $g_1(n) = n^2$ and $g_2(n) = n^3$. Growth rate of $g_1$ is less than that of $g_2$, i.e., $g_1(n) = O(g_2(n)).$

Options $A$ and $B$ are TRUE here.
edited by
9 9 votes

Yes. Both (a) and (b) are correct. $n^{2}$ is $O(n^{3})$.

edited by
1 1 vote
Index Condition $g_{1}(n)$ $g_{2}(n)$ Time Complexity($B$) Time Complexity($A$)
1 $0 \leq n \leq 100$ $n^{3}$ $n$ $O(n^{3})$ $O(g^{2}(n))$ -- Fails
2 $101 \leq n \leq 10000$ $n^{3}$ $n^{3}$ $O(n^{3})$ $O(g^{2}(n))$
3 $n \geq 10001$ $n^{2}$ $n^{3}$ $O(n^{3})$ $O(g^{2}(n))$

Thus the right option should be B

edited by
0 0 votes
In asymptotic complexity, we assume sufficiently large n. So, g1(n) = n2 and g2(n) = n3.
Growth rate of g1 is less than that of g2 i.e., g1(n) = O(g2(n)) = O(n).

Both A and B are True
0 0 votes
For asymptotic analysis, we assume sufficiently large value of n i.e n>10,000.

For this case, g1(n) = n^2, g2(n) = n^3

clearly, g1(n) = O(g2(n)) = O(n^3).
Answer:
Position:
Show:

Related questions

50 50 votes
7 answers 7 answers
16.0k
16.0k views
Kathleen asked Oct 4, 2014
16,005 views
Which of the following statements is false?Optimal binary search tree construction can be performed efficiently using dynamic programmingBreadth-first search cannot be us...
17 17 votes
2 answers 2 answers
7.9k
7.9k views
Kathleen asked Oct 5, 2014
7,890 views
An array $A$ contains $n$ integers in locations $A[0], A , \dots A[n-1]$. It is required to shift the elements of the array cyclically to the left by $K$ places, where $1...
21 21 votes
4 answers 4 answers
5.4k
5.4k views
Kathleen asked Oct 5, 2014
5,444 views
What function of $x$, $n$ is computed by this program?Function what(x, n:integer): integer: Var value : integer begin value := 1 if n 0 then begin if n mod 2 =1 then val...
41 41 votes
4 answers 4 answers
18.8k
18.8k views
Kathleen asked Oct 4, 2014
18,783 views
Consider the following heap (figure) in which blank regions are not in use and hatched region are in use.The sequence of requests for blocks of sizes $300, 25, 125, 50$ c...