Question

For each of the following six program fragments: a. Give an analysis of the running time (Big-Oh will do). b. Implement the c
(7) sum = 0; for(i=0; in; ++i) for(j = 0; j <i *i; ++j) for(k = 0k<j; ++) ++sum;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.) O(n)

time taken: 0 sec.

memory: 1.47 MB

2.) O(n^2)

time taken: 0 sec

memory: 1.4 MB

3.) O(n^3)

time taken: 0 sec

memory: 1.3 MB

4.) O(n)

time taken: 0.6 sec

memory: 1.470496 MB

5.) O(n^2)

time taken: 0.54 sec

memory: 1.470496 MB

6.) O(2^n)

time taken: 0 sec

memory: 1.470496 MB

7.) O(n^4)

time taken: 0 sec

memory: 1.470496 MB

Add a comment
Know the answer?
Add Answer to:
For each of the following six program fragments: a. Give an analysis of the running time...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Data Structures and Algorithms For each of the following program fragments, give an analysis of the...

    Data Structures and Algorithms For each of the following program fragments, give an analysis of the running time using Big-Oh notation. Do not give formulas, but analyze every line to calculate the running time, e.g. sum = 0 is equal to 1 unit time ... 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 =...

  • For each of the following two program fragments: a. Give an analysis of the running time...

    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);

  • 4. Big-Oh and Rune time Analysis: describe the worst case running time of the following pseudocode...

    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...

  • 8.         R-4.8 Order the following functions by asymptotic growth rate. 4nlogn + 2n 2^10    2^logn 3n...

    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...

  • In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running...

    In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n) for(int i=n-1; i >=0; i--){ for(int k=0; k < i*n; k++){ // do something that takes O(1) time } }

  • Give a big-Oh characterization, in terms of n,of the running time for each of the following...

    Give a big-Oh characterization, in terms of n,of the running time for each of the following code segments (use the drop-down): - public void func1(int n) { A. @(1). for (int i = n; i > 0; i--) { System.out.println(i); B. follogn). for (int j = 0; j <i; j++) System.out.println(j); c.e(n). System.out.println("Goodbye!"); D.@(nlogn). E.e(n). F.ein). public void func2 (int n) { for (int m=1; m <= n; m++) { system.out.println (m); i = n; while (i >0){ system.out.println(i); i...

  • Exercises • Determine running time for the following code fragments: (a) a = b + c;...

    Exercises • Determine running time for the following code fragments: (a) a = b + c; d = a + e; (b) sum = 0; for (i=0; i<3; i++) for (j=0; j<n; j++) sum++; (c) sum=0; for (i=0; i<n<n; i++) sum++; (d) for (i=0; i < n-1; i++) for (j=i+1; j <n; j++) { tmp = A[i][j]; A[i][j] = A[j] [i]; A[j][i] = tmp; (e) sum = 0; for (i=1; i<=n; i++) for (j=1; j<=n; j+=2) sum++;

  • For the following program fragment give a Big-O analysis of the running time. Briefly explain your...

    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...

  • 1.4.6 Give the order of growth (as a function of n) of the running times of...

    1.4.6 Give the order of growth (as a function of n) of the running times of each of the following code fragments: a, int sum=0; for (int k n: k > 0; k /= 2) for (int i 0; ǐ < k; İ++) sum++; b.int sum 0; for (int i = 1; i < n; i *= 2) for (int j = 0; j < i; j++) sum++; int sum = 0; for (int í = 1; i < n;...

  • In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running...

    In Big-Θ notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n) int *a = new int [10]; // new is O(1) int size = 10; for (int i = 0; i < n; i ++) { if (i == size) { int newsize = 3*size/2; int *b = new int [newsize]; // new is O(1) for (int j = 0; j < size; j ++)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT