Question: It should also randomly generate data to pass to the sorting methods. It should produce 40 data sets for each value of n, the size
It should also randomly generate data to pass to the sorting methods. It should produce 40 data sets for each value of n, the size of the data set and average the result of those 40 runs. The exact same data must be used for both sorting algorithms. It should also create 12 different sizes of data sets. Choose sizes that will clearly demonstrate the trend as n becomes large. Be sure that the data set sizes are evenly spaced
This project should consist of two separate programs. The first of those programs should perform the benchmarking described above and generate two data files, one for each of the two sorting algorithms.
The benchmarking program must be written to conform to the following design:
The purpose of the methods in the abstract class AbstractSort are as follows:
The method sort is an abstract method that must be implemented in both of your classes that contain the sorting methods that you have selected
The startSort method should be called before the sort begins and it should initialize the counter and record the starting time of the sort
The endSort method should be called after the sort ends and it should compute the elapsed time of the sort
The incrementCount method should be called whenever the critical operation that you selected is executed and it should increment the critical operation counter
The getCount method should return the final value of the counter
The getTime method should return the elapsed time
The output files should contain 12 lines that correspond to the 12 data set sizes. The first value on each line should be the data set size followed by 40 pairs of values. Each pair represents the critical element count and the time in nanoseconds for each of the 40 runs of that data set size. The values on each line should be delimited by spaces.
I am using a quick sort and merge sort methods. This is the code I have. I am having problems with the output files appearing in the created files sorts should work when call here but since the create file isn't working I'm not sure. thisis the code I have:
import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Random; import java.util.stream.IntStream; import javax.swing.*; import javax.swing.table.DefaultTableModel;
import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;
public class Report {
private static final int NUM_OF_DATASET_SIZES = 12; private static final int NUM_OF_RUNS = 40;
public static void main(String[] args) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Select the input file"); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); Scanner scanner; try { scanner = new Scanner(selectedFile); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(null, "File not found", "Error", JOptionPane.ERROR_MESSAGE); return; } int[] datasetSizes = new int[NUM_OF_DATASET_SIZES]; int[][] counts = new int[NUM_OF_DATASET_SIZES][NUM_OF_RUNS]; long[][] times = new long[NUM_OF_DATASET_SIZES][NUM_OF_RUNS]; for (int i = 0; i
//ApstractSort.java
import java.util.Random;
abstract class AbstractSort { int count = 0; long startTime, endTime;
abstract void sort(int[] data);
void startSort() { count = 0; startTime = System.nanoTime(); }
void endSort() { endTime = System.nanoTime(); }
void incrementCount() { count++; }
int getCount() { return count; }
long getTime() { return endTime - startTime; } } //Mergesort.java
class MergeSort extends AbstractSort { void sort(int[] data) { int n = data.length; if (n
private void merge(int[] left, int[] right, int[] data) { int i = 0, j = 0, k = 0; while (i
//QuickSort.java
class QuickSort extends AbstractSort { void sort(int[] data) { quickSort(data, 0, data.length - 1); }
private void quickSort(int[] data, int low, int high) { if (low
private int partition(int[] data, int low, int high) { int pivot = data[high]; int i = low - 1; for (int j = low; j
private void swap(int[] data, int i, int j) { int temp = data[i]; data[i] = data[j]; data[j] = temp; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
