Java coding question below: ***************************************************** (determining Big O) write a PerformanceTest class and compare the performance of mergesort and bubblesort. Use the following “PerfomanceTest” class example. Instead of the provided simpleLoop, method, use the mentioned sorting algorithms.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java coding question below:

*****************************************************

(determining Big O) write a PerformanceTest class and compare the performance of mergesort and bubblesort. Use the following “PerfomanceTest” class example. Instead of the provided simpleLoop,
method, use the mentioned sorting algorithms.
A) Test with an unsorted array (call the random(n) method to create a random array)
B) Test with a sorted array (call the sorted(n) method to create a sorted array)

Example: Consider the time complexity for the following simple loop:

for(int i= 1; i <= n; i++)
         k = k+5;
The complexity for this loop is O(n). To see how this algorithm performs, we run the perofmanceTest class to obtain the execution time for n = 1000, 10000, 100000, 100000

public class PerfomanceTest{
                 public static void main(String[] args) {

//              getTime(100000);
                 getTime(1000000);
}


public static void getTime(int n) {
           //int[] list = random(n);
           int[] list = sorted(n);
           long startTime = System.currentTimeMillis();
           simpleLoop(n);
           //bubbleSort(list);
          //mergeSort(list);
          long endTime = System.currentTimeMillis();
          System.out.println("Execution time for n = " + n + " is "
                               + (endTime - startTime) + " milliseconds.");
}


private static int[] random(int n) {
            int[] list = new int[n];
            for (int i = 0; i < n; i++) {
                        list[i] = (int) (Math.random() * 1000);
            }
            return list;
}


private static int[] sorted(int n) {
             int[] list = new int[n];
             for (int i = 0; i < n; i++)
                         list[i] = i;
              return list;
}


private static void simpleLoop(int n){
             int k = 0;
             for(int i= 1; i <= n; i++)
                         k = k+5;
}
}

Example Results:
Execution time for n = 1000000 is 6 milliseconds
Execution time for n = 10000000 is 61 milliseconds
Execution time for n = 100000000 is 610 milliseconds
Execution time for n = 1000000000 is 6048 milliseconds

This predicts a linear time complexity for this loop. When the input size increases 10 times, the runtime increases roughly 10 times.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 9 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education