Question

In: Computer Science

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 = i ++)

{           for ( j = 1 ; j <= i ; j ++)

            {           for (k=1;k<=j;++k)

            {          

                        cout<<”*”;

            }

}

}

Solutions

Expert Solution

Anaswers:

  1. O(log2n) or O((log n)2) Both are same
  2. O(n3)


Related Solutions

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
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]; } } }
What is time Complexity each of the following function? 1- void function(int n) {             for (int...
What is time Complexity each of the following function? 1- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n/2; j++)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 2- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n; j = 2 * j)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 3- void function(int n) {             for (int i=1; i<=n; i++)                           for (int j=1;...
1. Express the function f(t) = 0, -π/2<t<π/2                                  &nbsp
1. Express the function f(t) = 0, -π/2<t<π/2                                            = 1, -π<t<-π/2 and π/2<t<π with f(t+2π)=f(t), as a Fourier series.
Calculate the concentration of an aqueous solution of Ca(OH)2 that has a pH of 11.11. Express...
Calculate the concentration of an aqueous solution of Ca(OH)2 that has a pH of 11.11. Express your answer using two significant figures. [Ca(OH)2] =   M   SubmitMy AnswersGive Up
Question 15: Use the Master theorem to find the asymptotic complexity of the running time function...
Question 15: Use the Master theorem to find the asymptotic complexity of the running time function T(n) of the program in problem 14. --- Problem 14 --- def prob14(L): if len(L) <= 1: return 0 output = 0 for x in L: for y in L: output += x*y for x in L: output += x left = L[ 0 : len(L)//2 ] right = L[ len(L)//2 : len(L) ] return output + prob15(left) + prob15(right) ***Big-O, Omega, Theta complexity...
Purpose This project is meant to give you experience with sorting, binary searching, and Big-Oh complexity....
Purpose This project is meant to give you experience with sorting, binary searching, and Big-Oh complexity. Objective "Write in Java please" Your goal is to take a book, as a large text file, and build a digital “concordance”. A concordance is like an index for a book in that it contains entries for words in the book, but it also includes passages from the book containing that word. For example, a query for the word Dormouse in Alice in Wonderland...
2 algorithms for Prefix Averages, one that ran in big-Oh n2 time and a second that...
2 algorithms for Prefix Averages, one that ran in big-Oh n2 time and a second that ran in big-Oh n time. Code up methods for both algorithms. Show through different input examples and using the Current Time method call how the polynomial time algorithm runs slower than the linear time version. Use system.out.println statement to show your results. please who can help with this question In Java Thank you
Justify the following statements using the "big-Oh" definition: a) (n+25)2 is O(n2) , and n2 is...
Justify the following statements using the "big-Oh" definition: a) (n+25)2 is O(n2) , and n2 is O((n+25)2) b) n3 is NOT O(n2); c) Given f1(n) is (n+25)2 , and f2(n) is n3 what is the big-Oh for f1(n) x f2(n)?
Calculate the pH of a 0.10 M solution of barium hydroxide, Ba(OH)2. Express your answer numerically...
Calculate the pH of a 0.10 M solution of barium hydroxide, Ba(OH)2. Express your answer numerically using two decimal places. Calculate the pH of a 0.10 M solution of NaOHNaOH. Express your answer numerically using two decimal places. Calculate the pH of a 0.10 M solution of hydrazine, N2H4. Kb for hydrazine is 1.3×10−61.3×10−6. Express your answer numerically using two decimal places. Calculate the pH of a 0.10 M solution of hypochlorous acid, HOCl. Ka of HOCl is 3.5×10−8. Express...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT