Question: How to measure the average performance of sorting algorithms with different sizes and numbers(with arrayList ) and compare with a graph? I have these methods:

How to measure the average performance of sorting algorithms with different sizes and numbers(with arrayList) and compare with a graph?

I have these methods:

//This one receives one size(n) parameter

public static ArrayList RandomArray(int n){ ArrayList randomArray = new ArrayList(n); Random rand = new Random(); //--- random number rand.setSeed(System.currentTimeMillis()); for(int i = 0; i < n; i++ ) { //loop for creating random numbers until n size randomArray.add(i, Math.abs(rand.nextInt() % 256)); } return randomArray; }

//I have this one to show the Array

public static void ShowArray(ArrayList array) { for(int arrayItem : array) { System.out.println(arrayItem); }

}

//and this ones on my main

ArrayList arrayShow = RandomArray(4); // this one to create an ArrayList and using the method RandomArray with the n Size. System.out.println(arrayShow); ArrayList sortArrayA = new Sorting().SortX(arrayShow).; ArrayList sortArrayB = new Sorting().SortY(arrayShow); ArrayList sortArrayC = new Sorting().SortZ(arrayShow);

Now I have 3 sorting methods in a different file, how can I measure the performance of each algorithm, and compare? Where should I set a timer when I call each sort method, and should I create a loop to run like 5000 times so that I can compare?

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!