Question

In: Computer Science

Calculate the Big-O time complexity. Show work 1. n^2 + 3n + 2 2. (n^2 +...

Calculate the Big-O time complexity. Show work

1. n^2 + 3n + 2

2. (n^2 + n)(n ^2 + π/2 )

3. 1 + 2 + 3 + · · · + n − 1 + n

Solutions

Expert Solution

Calculate the Big-O time complexity of the following:

• The upper bound notation for the function F(n) is provided by the Big-OH (O) notation. For the all suitable large value of n, the function F(n) = O(g(n)) if we can prove following statement.

• O(g) is the set of function from non-negative integers to positive real numbers such that for some real constant C >0 and some non-integer constant number n0:

F(n) ≤ C * g(n) + n0 for all n ≥ n0

(1) n2 + 3n + 2

Time complexity: O(n2)

Description:

F(n) ≤ C * g(n) + n0 for all n ≥ n0

⇒ n2 + 3n + 2 ≤ n2 + 3n + n ;n ≥ 2

⇒ n2 + 3n + 2 ≤ n2 + 3n + n ;n ≥ 2

⇒ n2 + 3n + 2 ≤ n2 + 4n ;n ≥ 2

⇒ n2 + 3n + 2 ≤ n2 + n2 ;n2 ≥ 4n

⇒ n2 + 3n + 2 ≤ 2n2       ;n2 ≥ 4n

So, g(n) = n2 and C = 2

F(n) = O(g(n))

F(n) = O(n2)

(2) (n2 + n)(n2 + π/2)

Time complexity: O(n4)

Description:

(n2 + n)(n2 + π/2) = n4 + n3 + (π/2)n2 + (π/2)n

F(n) ≤ C * g(n) + n0 for all n ≥ n0

⇒ n4 + n3 + (π/2)n2 + (π/2)n  ≤  n4 + n3 + (π/2)n2 + n2 ; n2 ≥ (π/2)n

⇒ n4 + n3 + (π/2)n2 + (π/2)n  ≤  n4 + n3 + (π)n2   ; n2 ≥ (π/2)n

⇒ n4 + n3 + (π/2)n2 + (π/2)n  ≤  n4 + n3 + n3 ; n3 ≥ (π)n2

⇒ n4 + n3 + (π/2)n2 + (π/2)n  ≤  n4 + 2n3    ; n3 ≥ (π)n2

⇒ n4 + n3 + (π/2)n2 + (π/2)n  ≤  n4 + n4    ; n4 ≥ 2n3

⇒ n4 + n3 + (π/2)n2 + (π/2)n  ≤ 2n4    ; n4 ≥ 2n3

So, g(n) = n4 and C = 2

F(n) = O(g(n))

F(n) = O(n4)

(3) 1 + 2 + 3 + · · · + n − 1 + n

Time complexity: O(n2)

Description:

1 + 2 + 3 + · · · + n − 1 + n = n(n + 1)/2 = n2/2 + n/2

F(n) ≤ C * g(n) + n0 for all n ≥ n0

⇒ n2/2 + n/2 ≤ n2/2 + n2   ; n2 ≥ n/2

⇒ n2/2 + n/2 ≤ (3/2)n2 ; n2 ≥ n/2

So, g(n) = n2 and C = 3/2

F(n) = O(g(n))

F(n) = O(n2)


Related Solutions

Question 2: Calculate the time complexity function T(n) and express it in terms of big-Oh for...
Question 2: Calculate the time complexity function T(n) and express it in terms of big-Oh for the following code: Part a       (hint: make use of sum of geometric progression): for (int i=1; i <= n ; i = i*2) {           for ( j = 1 ; j <= i ; j ++)             {                       cout<<”*”;             } } Part b      (hint: make use of sum of square of a number sequence): for (int i=1; i <= n ; i...
6a. Show that 2/n = 1/3n + 5/3n and use this identity to obtain the unit...
6a. Show that 2/n = 1/3n + 5/3n and use this identity to obtain the unit fraction decompositions of 2/25 , 2/65 , and 2/85 as given in the 2/n table in the Rhind Mathematical Papyrus. 6b. Show that 2/mn = 1/ (m ((m+n)/ 2 )) + 1/ (n ((m+n)/ 2 )) and use this identity to obtain the unit fraction decompositions of 2/7 , 2/35 , and 2/91 as given in the 2/n table in the Rhind Mathematical Papyrus....
Give the asymptotic (“big-Oh”) running time complexity of the following algorithm, show all the work you...
Give the asymptotic (“big-Oh”) running time complexity of the following algorithm, show all the work you have done. Algorithm: ArrayMangle(A[ ], int n) Input: an array A, an integer n x = 0; for (i=0; i<=n-1; i++) { for (j=i; j<=n-1; j++) { x = x + A[j]; } for (k=0; k<= n-1; k++) { for (j=0; j< =n-1; j++) { x = x + A[j]*A[k]; } } }
If f(n) = 3n+2 and g(n) = n, then Prove that f(n) = O (g(n))
If f(n) = 3n+2 and g(n) = n, then Prove that f(n) = O (g(n))
Q1. A. What is the complexity of partition process in quick sort? O(1) O(logN) O(N) O(NlogN)...
Q1. A. What is the complexity of partition process in quick sort? O(1) O(logN) O(N) O(NlogN) B. Evaluate the following postfix expression. 2 3 4 + * C. In an array representation of heap, what are the parent node of a node a[10]? a[9] a[11] a[5] a[20] There is no easy way to access parent node in such representation. D. In an array representation of heap, what are the children nodes (if any) of a node a[10]? a[11] and a[12]...
PYTHON Write the time complexity of the code snippets in Big O notation. Also, add one/two...
PYTHON Write the time complexity of the code snippets in Big O notation. Also, add one/two lines to explain your answer. 1a int a = 0, b = 0; for (int i = 0; i< N; i++) {     a = a + i; } for (int j = 0; j < N; j++) {     b = b + j; } 1b bool isPrime(int N) { if (N == 1) return false; for (x = 2; x <= sqrt(N);...
how do i find a peak in time complexity of O(log(n)) in a list? input: a...
how do i find a peak in time complexity of O(log(n)) in a list? input: a list of numbers or integers output: a possible local peak in the list for an example: calling function [2,3,8,9,5] would return 3 im thinking about using binary search but it would require a sorted list.
* Add operation counts -    * f(N) formula (show your work) -    * O(N)...
* Add operation counts -    * f(N) formula (show your work) -    * O(N) reduction -    */    public static long sum4(int N)//f(N) = ; O(N) =    {        long opCount = 0;        long sum = 0; // 1        for(int i = 0; i < N; i++)        {            for(int j = 0; j < i; j++)            {                sum++;   ...
Derive the Sackur-Tetrode equation starting from the multiplicity givenin Ch. 2: Ω =(1/N!)(V^{N}/h^{3N})(pi^{3N/2}/3N^{2}!)(2mU)^{3N/2} The Sackur-Tetrode equation...
Derive the Sackur-Tetrode equation starting from the multiplicity givenin Ch. 2: Ω =(1/N!)(V^{N}/h^{3N})(pi^{3N/2}/3N^{2}!)(2mU)^{3N/2} The Sackur-Tetrode equation is: S=Nk[ln((V/N)((4pi*m*U)/(3Nh^{2}))^{3/2})+(5/2)]
   * Add operation counts    * f(N) formula (show your work)    * O(N) reduction...
   * Add operation counts    * f(N) formula (show your work)    * O(N) reduction    */    public static long sum3(int N)//f(N) = ; O(N) =    {        long opCount = 0;        long sum = 0;        for(int i = 0; i < N; i++)        {            for(int j = 0; j < N*N; j++)            {                sum++;            }   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT