Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is topology? Explain with examples

Answered: 1 week ago