preview

Assignment Notes : Public Class Benchmarking Techniques

Satisfactory Essays

package assignment unit 1; import java.util.*; public class BenchmarkingSortingAlgorithms { // Here I compute banchmarks of two different sorting techniques intmaxArraySize=10000; // Array Size int[] sortingArray1 = new int[maxArraySize]; // First Array int[] sortingArray2 = new int[maxArraySize]; // Second Array public BenchmarkingSortingAlgorithms(){ //The class Constructor for (int i = 0; i< sortingArray1.length; i++) { // Fill two arrays with the same random numbers. sortingArray1[i]=(int)(Integer.MAX_VALUE * Math.random()); sortingArray2[i]=sortingArray1[i]; } long startTimeArray1 = System.currentTimeMillis(); // Start computing time for SelectionSort selectionSort(sortingArray1); // Sorting Array1 with SelectionSort long …show more content…

You are familiar with simple sorting algorithms such as insertion sort and selection sort. (See Section 7.4 in the textbook.) While these methods work fine for small arrays, for larger arrays they can take an unreasonable amount of time. The question is whether we can do any better. Java has some built-in sorting methods. They can be found in the class named Arrays in the package java.util. The one that you will use in this lab is Arrays.sort(A), which sorts the entire array A into increasing order. (Actually, there are different methods for different array base types, but all the methods have the same name and are used in the same way. You will be using an array of ints in this lab.) You should write a program that does the following: - Create two arrays of type int[]. Both arrays should be the same size, and the size should be given by a constant in the program so that you can change it easily. - Fill the arrays with random integers. The arrays should have identical contents, with the same random numbers in both arrays. To generate random integers with a wide range of sizes, you could use (int)(Integer.MAX_VALUE * Math.random()). - Sort the first array using either Selection Sort or Insertion Sort. You should add the sorting method

Get Access