Question

Provide a "big oh" run-time analysis for each of the following. When a value of “n” is used, it is the size of the input.4.) void problem 40 cin n min max for (int i min i n, i++) for (int j- 1: j< max, j++) tota while (total n tota total 2 total 5.) void problem 50 cin n; for (int i 0: i n, i++) for (int j 0; j i2; j++) for (int k 0; k <j2; k++) sushi salmon tuna mackeral total

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

4) if you see there is nested loop

since the i loop goes from min to n
and j loop goes from 1 to max
so complexity is o(n * max)
and there is also whileloop after the nested loop which goes to n
so complexity is O(n)
so total complexity is O(n * max) +O(n) = O(n)

5)
There is 3 nested loop
i loop goes from 0 to n ==> complexity is O(n)
j loop goes from 0 to i2 ==> since maximum value of i is n
so j loop goes to n2 ==> so complexity is O(n2)

K loop goes from 0 to j2 ==> since maximum value of j is n2
so k loop goes to n4 ==> so complexity is O(n4)

so total complexity is O(n * n2 *n4 ) = O(n7)

Add a comment
Know the answer?
Add Answer to:
Provide a "big oh" run-time analysis for each of the following. When a value of “n”...
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
  • 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...

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

  • Show how to get the big-Oh for the following code: void CountSort (int A[N], int range)...

    Show how to get the big-Oh for the following code: void CountSort (int A[N], int range) { // assume 0 <= A[i] < range for any element A[i] int *pi = new int[range]; for ( int i = 0; i < N; i++ ) pi[A[i]]++; for ( int j = 0; j < range; j++ ) for ( int k = 1; k <= pi[j]; k++ ) cout << j << endl; }

  • (10') 6. For each of the following code blocks, write the best (tightest) big-o time complexity...

    (10') 6. For each of the following code blocks, write the best (tightest) big-o time complexity i) for (int i = 0; ǐ < n/2; i++) for (int j -0: ni j++) count++ i) for (int í = 0; i < n; i++) for (int ni j0 - for (int k j k ni kt+) count++ İİİ) for (int í ー 0; i < n; i++) for(int j = n; j > 0; j--) for (int k = 0; k...

  • In this assignment you will implement merge-sort algorithm by creating 2 threads instead of 2 pro...

    In this assignment you will implement merge-sort algorithm by creating 2 threads instead of 2 processes. First half of the array will be sorted by thread 1 and the second half by thread 2. When the threads complete their tasks, the main program will merge the half arrays. You should not waste your time on merge-sort algorithm. Use the merge sort algorithm given below void mergesort(int a[],int i,int j) { int mid; if(i<j) { mid=(i+j)/2; mergesort(a,i,mid); //left recursion mergesort(a,mid+1,j); //right...

  • Describe the worst case running time of the following pseudocode functions in Big-Oh notation in terms...

    Describe the worst case running time of the following pseudocode functions in Big-Oh notation in terms of the variable n. Show your work b) void func(int n) { for (int i = 0; i < n; i = i + 10) { for (int j = 0; j < i; ++i) { System.out.println("i = " + i); System.out.println("j = " + j);

  • Please give a output Linux/Ubuntu and how to run it (compile) this program ,my assigment is below...

    Please give a output Linux/Ubuntu and how to run it (compile) this program ,my assigment is below : : Merge Sort algorithm using 2 processes a.) Define an integer array of 100 integers. Populate this array with random numbers. You can use int rand(void); function. Do not forget to initialize this function. You will sort the numbers in the array using merge-sort algorithm. In merge sort algorithm the half of the array will be sorted by one process and second...

  • For each of the below code snippets, identify the bounding function (the big O) of the...

    For each of the below code snippets, identify the bounding function (the big O) of the number of times the indicated line is run (justify your answer briefly): int i = 1: while (i < n) { printf ("Insert difficult work here!") i = i + i: } for(i = 0: i < n: i++) { for (j = 0: j < n: j++) { for (k = 0: k < n: k++) { if(i==j && j==k) arr[i] [j] [k]...

  • find complexity Problem 1 Find out the computational complexity (Big-Oh notation) of the code snippet: Code...

    find complexity Problem 1 Find out the computational complexity (Big-Oh notation) of the code snippet: Code 1: for (int i = n; i > 0; i /= 2) { for (int j = 1; j < n; j *= 2) {     for (int k = 0; k < n; k += 2) {               // constant number of operations here     } } } Code 2: Hint: Lecture Note 5, Page 7-8 void f(int n) { if (n...

  • Determine the Big 0 provide the order (Big O) of the execution speed also determine the...

    Determine the Big 0 provide the order (Big O) of the execution speed also determine the exact execution speed. public class CountIt { public long SnippetNestedLoop(long n) { long i, j, x = 0; i=0; x++; while(i<n){ x++; //i<n // SomeStatement // j = 0; // j < n // SomeStatement // j++; // Can you explain why is this here? // i++; // Can you explain why is this here? Ans: i < n } } } x++; return...

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
ADVERTISEMENT