Question

Analyze the following code and provide a "Big-O" estimate of its running time in terms of...

Analyze the following code and provide a "Big-O" estimate of its running time in terms of n. Explain your analysis. Assume k is a constant given by the problem.

for (i=1; i<=n; i++)

     p = pow(i,k); // p = i to the power of k

     for (j=1; j<=p; j++)

          Some O(1) work

     end for

  end for

0 0
Add a comment Improve this question Transcribed image text
Answer #1

for i=1, j loop runs 1k times

for i=2, j loop runs 2k times

for i=3, j loop runs 3k​​​​​​​ times

for i=4 j loop runs 4k​​​​​​​ times

'

'

'

for i=n, j loop runs nk​​​​​​​ times

sum is 1k+2k+3k+-------+ nk

=O(nk+1)

Add a comment
Know the answer?
Add Answer to:
Analyze the following code and provide a "Big-O" estimate of its running time in terms of...
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
  • 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 } }

  • 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 ++)...

  • Q-1: Given the following code fragment, what is its Big-O running time? test = 0 for...

    Q-1: Given the following code fragment, what is its Big-O running time? test = 0 for i in range(n):             for j in range(n):                         test= test + i *j Q-2: Given3 the following code fragment what is its Big-O running time? for i in range(n):             test=test+1 for j in range(n):             test= test - 2 Q-3: Given the following code fragment what is its Big-O running time? i = n while i > 0:             k=2+2             i...

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

  • Analyze the following code fragments and write down the Big-O estimates of the following code fragments....

    Analyze the following code fragments and write down the Big-O estimates of the following code fragments. Provide a concise explanation how you got your answer. c. for (int j = 0; j < n; j++) {     for (int k = 0; k < n; k++)          cout << (j + k) << endl; } d. while (n > 1) {    k += n *3; n = n / 2; } e. int temp = n; for (int j...

  • Analyze the following code fragments and write down the Big-O estimates of the following code fragments....

    Analyze the following code fragments and write down the Big-O estimates of the following code fragments. Provide a concise explanation how you got your answer. c. for (int j = 0; j < n; j++) {     for (int k = 0; k < n; k++)          cout << (j + k) << endl; } d. while (n > 1) {    k += n *3; n = n / 2; } e. int temp = n; for (int j...

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

  • Using C++ please explain What is the Big-O time complexity of the following code: for (int...

    Using C++ please explain What is the Big-O time complexity of the following code: for (int i=0; i<N; i+=2) { ... constant time operations... Select one: o a. O(n^2) O b. O(log n) c. O(n) O d. 0(1) What is the Big-O time complexity of the following code: for(int i=1; i<N; i*=2) { ... constant time operations... Select one: O O a. O(n^2) b. 0(1) c. O(n) d. O(log n) O What is the Big-O time complexity of the following...

  • Compute the total running time for each of the functions in the following code. First, compute...

    Compute the total running time for each of the functions in the following code. First, compute the running time in terms of some constants a, b, c, d, e, etc. Show your work and give the answer in the text box. Then give the tightest big-O bound you can for each. (All of the functions are O(n!), but you can give a more informative bound for each.) void f(int n) {   int i = 1;   while (i <= sqrt(n)) {...

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

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