Question

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 terms of n, of the running time of the example 3 method shown in Code Fragment 4.12.

12.       R-4.12 Give a big-Oh characterization, in terms of n, of the running time of the example 4 method shown in Code Fragment 4.12.

13.       R-4.13 Give a big-Oh characterization, in terms of n, of the running time of the example 5 method shown in Code Fragment 4.12.

/?? Returns the sum of the integers in given array. ?/

public static int example1(int[ ] arr) {

int n = arr.length, total = 0;

for (int j=0; j < n; j++)

total += arr[j];

return total;                   // loop from 0 to n-1

/?? Returns the sum of the integers with even index in given array. ?/

public static int example2(int[ ] arr) {

int n = arr.length, total = 0;

for (int j=0; j < n; j+=2)

total += arr[j];

return total;                       // note the increment of 2

}

/** Returns the sum of the prefix sums of given array. */
public static int example3 (int [] arr) {

int n = arr.lenght, total = 0;
for (int j=0;j <n; j++)       //loop from 0 to n-1
for (int k=0; k<= j; k++)   // loop from 0 to j

total +=arr[j];

return total;

}

/** returns the sum of the prefix sums of given array. */
public static int example4 (int[] arr){

int n = arr.lenght, prefix = 0, total = 0;
for int j= 0; j < n ; j++){              //loop from 0 to n-1

prefix += arr[j];

total += prefix;
}
return total;
}

/**returns the number of times second array stores sum of prefix sums from first*/

public static int example5(int[] first, int[] second){     //assume equal length arrays

int n = first.lenght, count=0;

for (int i=0; i<n; i++){    //loop from 0 to n-1

int total= 0;

for (int j=0; j<n; j++)       //loop from 0 to n-1

     for(int k = 0; k<= j; k++)                    //loop from 0 to j

      total +=first[k];

if (second[i] == total) count++;

}

return count;

}

Code Fragment 4.12: Some sample algorithms for analysis.

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

As per HOMEWORKLIB POLICY, I am answering only 4 questions. In order to get the solution of remaining questions, please upload them again.

9.) since j runs from 0 to n-1. Therefore, its running time is O(n).

10.) since j runs from 0 to n-1 but with increment of 2. So, it will run for n/2 times which is O(n).

11.) Inner for loop runs as

1 + 2 + 3+ ... + n-1 = n*(n+1)/2 which is O(n^2).

12.) since j runs from 0 to n-1. Therefore, its running time is O(n).

13.) since i runs from 0 to n-1. Therefore, its running time is O(n).

nner for loop runs as

1 + 2 + 3+ ... + n-1 = n*(n+1)/2 which is O(n^2).

Now, O(n) + O(n^2) = O(n^2).

Add a comment
Know the answer?
Add Answer to:
8.         R-4.8 Order the following functions by asymptotic growth rate. 4nlogn + 2n 2^10    2^logn 3n...
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
  • Prove Big O in terms of nₒ and C? There are 5 examples: class Exercise {...

    Prove Big O in terms of nₒ and C? There are 5 examples: class Exercise { public static int example1(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j++) // loop from 0 to n-1 total += arr[j]; return total; } public static int example2(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j += 2) // note the increment of 2 total += arr[j]; return...

  • I need to program 3 and add to program 2 bellows: Add the merge sort and...

    I need to program 3 and add to program 2 bellows: Add the merge sort and quick sort to program 2 and do the same timings, now with all 5 sorts and a 100,000 element array. Display the timing results from the sorts. DO NOT display the array. ____________________>>>>>>>>>>>>>>>>>>>>___________________________ (This is program 2 code that I did : ) ---->>>>>> code bellow from program 2 java program - Algorithms Write a program that randomly generates 100,000 integers into an array....

  • Calculating prefix average of a set of values is an important problem, especially in financial calculations....

    Calculating prefix average of a set of values is an important problem, especially in financial calculations. Use the following link to understand background on prefix averages problem - http://csfundamentals.com/tech-interview/dsa/prefix-averages-algorithm-java-program.php Consider the algorithms (methods) – prefixAverage1 and prefixAverage2 for calculating prefix averages. The source code is given to you. Implement both the algorithms and perform an experiment analysis of their running times under different input sizes. Visualize the running times on a chart, where x-axis represents different input sizes and y-axis...

  • Student Name Student ID CS209 Data Structures and Algorithms - Quiz 1/2e Friday, Feb 22, 2019...

    Student Name Student ID CS209 Data Structures and Algorithms - Quiz 1/2e Friday, Feb 22, 2019 1. (25 points) Here is an array of five integers: 5,3,4,2,1 Please draw this array after EACH iteration of the large loop (outer loop) in a Bubble sort (sorting smallest to largest). (25 points) Here is an array of five integers: 5,3,4,2,1 Please draw this array after EACH iteration of the large loop (outer loop) in a Selection sort (sortin from smallest to largest)....

  •   Given a bubble sort and the following array: [10,7,19,5,16] What are the values after the first...

      Given a bubble sort and the following array: [10,7,19,5,16] What are the values after the first iteration? Given an insertion sort and the following array: [50,5,35,70,6] What does the array look like after the first insertion:    Fill in the missing code for InsertionSort method // Insertion Sort method //sorts an array of Auto objects public static void insertionSort(Auto [] arr) { Auto temp; int j; for (int i=1; i<arr.length; i++) {     j=i;     temp=arr[i];                while (j!=0 &&(temp.getModel().compareTo(arr[[j-1].getModel())<0)...

  • Create an ArrayListReview class with one generic type to do the following • Creates an array...

    Create an ArrayListReview class with one generic type to do the following • Creates an array list filled with the generic type of the ArrayListReview class, and inserts new elements into the specified location index-i in the list. (5 points) • Create a method inside the class to implement the calculation of Fibonacci numbers. Use System.nanoTime to find out how much time it takes to get fab(50). Create a method inside the class to check if an array list is...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • What is the Big-Oh order of the following code fragment? The fragment is parametrized on the...

    What is the Big-Oh order of the following code fragment? The fragment is parametrized on the variable N. Assume that you are measuring the number of times j is decremented. public static void sort(Comparable[] a) { int N-a.length; for (int i = 1; i < N;i++) { for (int j = i; j > && less(a[5], a[j-1]); j--) //measure j -- exch(a, j, j-1); O(nlogn) O O(n^2) Q(n) Does not exist.

  • Consider the following code segment. int[]arr={1, 2, 3, 4, 5, 6, 7, 8}; for(int k=3; k<arr.length-1;...

    Consider the following code segment. int[]arr={1, 2, 3, 4, 5, 6, 7, 8}; for(int k=3; k<arr.length-1; R++ arr[k]-arr[k+1]; What are the contents of arr as a result of executing the code segment? a. {1, 2, 3, 5, 6, 7, 8, 8) b. {2, 2, 4, 5, 6, 7, 8, 8} C. {2, 4, 6, 5, 6, 7, 8,8} d. {4, 2, 4, 4, 6, 7, 8, 8) e. {6, 6, 4, 5, 6, 7, 8, 8} int) arr={7, 2.5, 3.0,...

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