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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started