How do you perform the timing tests for sorting and how do you properly code it?

Yhchf97
timer Asked: Oct 12th, 2018

Question Description

I need to find the timing results for bubble, selection and insertion sort from the given code and put them into an excel spreadsheet. The results have to be calculated from random, ascending order and descending order. I would also need to edit the performance testing code so that there are no timing errors or something. The timing results are outputted as milliseconds. Once I finish calculating and make line graphs for the results, I need to make a conclusion for them. So the one thing that I am asking for help on is the coding part. The files I am uploading are directions for the assignment, so that you understand what it is. The codes I have been given by my professor and the excel spreadsheet I need to use to put the results in.

Unformatted Attachment Preview

Directions for Testing the Simple Sorts First understand the simple sorts; bubble sort, insertion sort, and selection sort. Make sure that you know the algorithms for these sorts. Look at the visual displays for these sorts and write out the steps for the algorithm on a separate document, or into the spreadsheet used to test the simple sorts. You will turn in these algorithms for the simple sorts. We will write some of the Insertion Sort, Bubble Sort, and Selection Sort algorithms together in class. Make sure that the algorithms you wrote are correct. We will then look at the code for these 3 simple sorts. We will compare it to the algorithms we have written and understand the code as a representation of the algorithms. Then we will do some timing tests on these sorts. For each sort run it with increasing number of items in the array. Run it with 100 items, 1,000 items, 10,000 items, 100,000 items, 1,000,000 items and 10,000,000 items. Record the time that it takes to complete the code for each test into the spreadsheet “ComparingSimpleSorts.xlsx”. Make a line graph that displays the results of your tests. Now change the for-loop in your “SimpleSortTest.java” file so that you are inserting numbers in ascending order. So the items in the array that you are soring are already sorted, instead of being random. For each sort run it again with 100 items, 1,000 items, 10,000 items, 100,000 items, 1,000,000 items and 10,000,000 items. Record the time that it takes to complete the code for each test into the spreadsheet “ComparingSimpleSorts.xlsx”. Make a line graph that displays the results of your tests. Now change the for loop in your “SimpleSortTest.java” file so that you are inserting numbers in descending order. So they are already sorted, but backwards, instead of being random or in order. For each sort run it again with 100 items, 1,000 items, 10,000 items, 100,000 items, 1,000,000 items and 10,000,000 items. Record the time that it takes to complete the code for each test into the spreadsheet “ComparingSimpleSorts.xlsx”. Make a line graph that displays the results of your tests. Now comes the fun part. Think of some intelligent conclusions that you can make about this experiment. Write your conclusions into the spreadsheet “ComparingSimpleSorts.xlsx” on the last page which is named Conclusion. Think about when each sort works well, and when they do not work well. Why do they work well – what in the code makes it work better or worse? Which sort performed the best overall? It is important that you explain the “why” of your intelligent conclusions. package testSort; public class PerformanceTest { public static void main(String[] args) { getTime(100); getTime(1000); getTime(10000); getTime(100000); getTime(1000000); getTime(10000000); } public static void getTime(long n) { long startTime = System.currentTimeMillis(); long k = 0; for (int i = 1; i list[i + 1]) { countBubbleSortSwaps++; // Swap list[i] with list[i + 1] int temp = list[i]; list[i] = list[i + 1]; list[i + 1] = temp; needNextPass = true; // Next pass still needed } } } }//end bubble sort /** The method for sorting the numbers */ /*public static void selectionSort(int[] list) { for (int i = 0; i < list.length - 1; i++) { countSelectionSortComparisons++; // Find the minimum in the list[i..list.length-1] int currentMin = list[i]; int currentMinIndex = i; for (int j = i + 1; j < list.length; j++) { countSelectionSortComparisons+=2; if (currentMin > list[j]) { currentMin = list[j]; currentMinIndex = j; } } // Swap list[i] with list[currentMinIndex] if necessary; countSelectionSortComparisons++; if (currentMinIndex != i) { list[currentMinIndex] = list[i]; list[i] = currentMin; countSelectionSortSwaps++; } } }//end selection sort /** The method for sorting the numbers */ /*public static void insertionSort(int[] list) { for (int i = 1; i < list.length; i++) { countInsertionSortComparisons++; int currentElement = list[i]; int k; for (k = i - 1; k >= 0 && list[k] > currentElement; k--) { list[k + 1] = list[k]; } // Insert the current element into list[k+1] list[k + 1] = currentElement; } }*/ public static void main(String[] args) { System.out.println("Bubble Sort"); for(int n = 100; n
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Related Tags

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors