JAVA NETBEANS CODE Let me see who can do this code so i can compare to mines. Th
ID: 3771231 • Letter: J
Question
JAVA NETBEANS CODE
Let me see who can do this code so i can compare to mines.
This chapter and previous chapters describe five sorting algorithms – bubble sort, selection sort, insertion sort, merge sort and quicksort. This chapter provides the merge sort and quicksort code. The previous chapters provide the bubble sort code and pseudocode for selection sort and insertions sort. Your assignment for the last chapter was to create software for either insertion sort or selection sort.
Your task here is to conduct benchmarking to compare the algorithms. You should try to run at least four of the five the sorting methods with random data sets of 10,000 20,000 100,000 200,000 1,000,000 and 2,000,000 items, 10 times each. You should stop the program for the first trial of any sorting method that takes more than 15 minute to run and report this result. If a sorting algorithm takes too long for one trial, such as for 100,000 items, then it is not necessary to complete the trials for larger data sets, simply report the size of the data set for which that algorithm started to take too long.
Explanation / Answer
import java.util.Random;
public class MySelectionSort {
public static int[] doSelectionSort(int[] arr){
for (int i = 0; i < arr.length - 1; i++)
{
int index = i;
for (int j = i + 1; j < arr.length; j++)
if (arr[j] < arr[index])
index = j;
int smallerNumber = arr[index];
arr[index] = arr[i];
arr[i] = smallerNumber;
}
return arr;
}
public static void main(String a[]){
int[] arr1 = new int[1000000];
Random rand=new Random();
for(int i=0;i<10000;i++)
{
arr1[i]=rand.nextInt(10000);
}
int[] arr2 = doSelectionSort(arr1);
for(int i:arr2){
System.out.print(i);
System.out.print(", ");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.