Question: Algorithms - Run each of the 3 loops below. Note: Use the following to help time the following questions long startTime = System.nanoTime() ; //call

Algorithms - Run each of the 3 loops below. Note: Use the following to help time the following questions long startTime = System.nanoTime() ; //call to method long endTime = System.nanoTime() ; long totalTime = endTime - startTime; System.out.println(totalTime); Loop 1: public static int run(int n) { int sum = 0; for (int i=0 ; i < n ; i++) for (int j=0 ; j < n ; j++) sum++; return sum; } a. What is the Big-Oh running time? b. Run the code with several values of N. c. Create a table with at least 5 different values of N with the run time in nanoseconds.

Loop 2: public static int run(int n) { int sum = 0; for (int i=0 ; i < n ; i++) for (int j=0 ; j < n * n ; j++) sum++; return sum; } a. What is the Big-Oh running time? b. Run the code with several values of N. c. Create a table with at least 5 different values of N with the run time in nanoseconds.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!