Data Structures and Algorithms
b.
sum = 0;
for( i = 0; i < n; i++)
for( j = 0; j < i*i; j++)
for( k = 0; k < j; k++)
sum++;
c.
sum = 0;
for( i = 0; i < n2; i++)
for( j = 0; j < i; j++)
sum++;
d,
sum = 0;
for( i = 0; i < 2n; i++ )
for( j = 0; j < i; j++ )
sum++;
b)answer)
sum = 0;
for( i = 0; i < n; i++)
for( j = 0; j < i*i; j++)
for( k = 0; k < j; k++)
sum++;
sum=0 take one unit of time.so it is written as O(1)
for i=0 ,j loop runs 0 times so k loop runs 0 times
for i=1,j loop runs 1 time.so k loop runs 1 time
for i=2,j values are 0,1,2,3,4.
when j=0 ,k loop runs for 0 times
when j=1 ,k loop runs for 1 times
when j=2 ,k loop runs for 2 times
when j=3 ,k loop runs for 3 times
when j=4 ,k loop runs for 4 times
here total k loop runs for 0+1+2+3+4=4*(4+1)/2 times
..........
for i=n,j values are 0,1,2,3,4,.....n^2
when j=0 ,k loop runs for 0 times
when j=1 ,k loop runs for 1 times
when j=2 ,k loop runs for 2 times
when j=3 ,k loop runs for 3 times
when j=4 ,k loop runs for 4 times
....
when j=m*m ,k loop runs for n*n times
here total k loop runs for
0+1+2+3+4+....+m*m=m2(m2+1)/2 times
total work is
time complexity=O(n5)
c)answer)
sum = 0;
for( i = 0; i < n^2; i++)
for( j = 0; j < i; j++)
sum++;
for i=0, j loop runs for 0 times
for i=1, j loop runs for 1 times
for i=2, j loop runs for 2 times
...
for i=n^2, j loop runs for n^2 times
sum=0 and sum++ take one unit of time.
total j loop runs for 1+2+3+4+.....+n^2
=n^2 *(n^2 +1)/2
total time complexity is O(n^4)
d)answer)
sum = 0;
for( i = 0; i < 2^n; i++ )
for( j = 0; j < i; j++)
sum++;
for i=0, j loop runs for 0 times
for i=1, j loop runs for 1 times
for i=2, j loop runs for 2 times
...
for i=2^n, j loop runs for 2^n times
sum=0 and sum++ take one unit of time.
total j loop runs for 1+2+3+4+.....+2^n
=2^n *(2^n +1)/2
total time complexity is O(22n)
Data Structures and Algorithms For each of the following program fragments, give an analysis of the...
For each of the following six program fragments: a. Give an analysis of the running time (Big-Oh will do). b. Implement the code in the language of your choice, and give the running time for several values of N. Pseudo Code Implementation Analysis of runtime time (Big-Oh) (1) sum = 0; for(i = 0; i < n; ++i) ++sum; (2) sum = 0; for(i = 0; i < n; ++i) for(j = 0; j<n; ++i) ++sum; (3) sum = 0;...
For each of the following two program fragments: a. Give an analysis of the running time (Big-Oh will do). (1) std::vector<int> my_vect; for( i = 0; i < n; i++ ) my_vect.insert(0, i); (2) std::vector<int> my_vect; for( i = 0; i < n; i++ ) my_vect.push_back(i); (3) std::list<int> my_list; for( i = 1; i < n; i++ ) my_list.insert(i, 0); (4) std::list<int> my_list; for( i = 1; i < n; i++ ) my_list.push_front(i);
For the following program fragment give a Big-O analysis of the running time. Briefly explain your answer: int t = 0; for(int i=1; i <= n; i++) for(int j=1; j <= i*i; j++) if(j % i == 0) t++; What I have so far, O(1) + O(n) + O(n2) + O(1) + O(1) Drop Low order terms: O(n) + O(n2) And I believe the final answer to be O(n3), but not sure if just drop the O(n) or...
8. R-4.8 Order the following functions by asymptotic growth rate. 4nlogn + 2n 2^10 2^logn 3n + 100logn 4n 2^n n^2 + 10n n^3 nlogn 9. R-4.9 Give a big-Oh characterization, in terms of n, of the running time of the example 1 method shown in Code Fragment 4.12. 10. R-4.10 Give a big-Oh characterization, in terms of n, of the running time of the example 2 method shown in Code Fragment 4.12. 11. R-4.11 Give a big-Oh characterization, in...
1 question) Arrange the following in the order of their growth rates, from least to greatest: (5 pts) n3 n2 nn lg n n! n lg n 2n n 2 question)Show that 3n3 + n2 is big-Oh of n3. You can use either the definition of big-Oh (formal) or the limit approach. Show your work! (5 pts.) 3 question)Show that 6n2 + 20n is big-Oh of n3, but not big-Omega of n3. You can use either the definition of big-Omega...
4. Big-Oh and Rune time Analysis: describe the worst case running time of the following pseudocode functions in Big-Oh notation in terms of the variable n. howing your work is not required (although showing work may allow some partial t in the case your answer is wrong-don't spend a lot of time showing your work.). You MUST choose your answer from the following (not given in any particular order), each of which could be re-used (could be the answer for...
What does a run-time analysis usually countS pts a. The number of arithmetic and other operations required fot the b. The number of megabytes required for the program to run c. The number of seconds required for the program to run. d. The number of seconds plus the number of megabytes Total 100 points, 30 ins and other operations required for the program to rn 2. What do we call an input that results in the longest execution timet a....
Hello, I would like to get help with the following algorithms and their respective analysis of runtime along with their recurrence equations, thanks in advance. 1. Analyze each of the following algorithms by providing a tight big-Oh bound on the run time with respect to the value n. Create a recurrence equation. a. void padawan(int n) { if( n <= 10 ) time++; else { for(int i=0; i<n; i++) time++; padawan(n/3); padawan(n/3); padawan(n/3); } } b. void nerfHerder(int n)...
Compute the time complexity for each of the following two program fragments with respect to N. Show your steps in reaching your answer. 1) for(i=1; i < N; i = i*2) { for(j=0;j // Operations with constant time… } } 2) for(i = 0; i < sqrt(N); i++){ for(j=1; j < i+8; j++){ for(k=0;k // Operations with constant time… } } }
1. (25 points) Assume each expression listed below represents the execution time of a program Express the order of magnitude for cach time using big O notation. a. T(n) = ns + 100n . log2 n + 5000 b. T(n) = 2" +n” + 7 d. T(n) 1+2+4+2 2 (75 points+5 extra credit) For cach of the code segments below, determine an equation for the worst-case computing time Tn) (expressed as a function of n, ie. 2n+4) and the order...