Question: please help with this 3 loops Analyze these Algorithms - Run each of the 3 loops below. Note: Use the following to help time the

please help with this 3 loops

Analyze these 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 milliseconds.

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

Loop 3:

Create your own loop! (write the code here)

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

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!