Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ or JAVA ONLY The purpose of the programming assignment is to perform empiric

ID: 641999 • Letter: C

Question

C++ or JAVA ONLY

The purpose of the programming assignment is to perform empirical analysis of the following sorting algorithms on integer arrays:

a. selection sort;

b. insertion sort;

c.two versions of a bubble sort: with and without counting the number of swaps on each pass through an array;

d. quicksort;

e. mergesort.

Requirements:

functions from standard libraries implementing sorting algorithms are NOT allowed; however, you can use any code from any other sources;

for obtaining the working time of each algorithm for a particular array, use the same function as for project #1. Call this function before and after a call to the function implementing a sorting algorithm;

run your functions for the following types of arrays containing 100, 1000 and 10000 integers: random numbers, sorted list, almost sorted list (say, each 10th number is out of order);

the size of integers is supposed to be from 1 to 10000;

store original arrays in the FILES;

please, do NOT include original and sorted arrays in your output!

Explanation / Answer

import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.*; import java.nio.file.Files; import java.util.ArrayList; /** * Runs each sorting algorithm 10 times with arrays of length: * 100 | 1,000 | 10,000 | 100,000 | 1,000,000 | 10,000,000 * public class RunSortingAlgorithms { //Create my arrays public static int[] INT_ARRAY_1000 = new int[1000]; public static int[] INT_ARRAY_10000 = new int[10000]; public static int[] INT_ARRAY_100000 = new int[100000]; public static int[] INT_ARRAY_1000000 = new int[1000000]; public static int[] INT_ARRAY_2000000 = new int[2000000]; //Put them in an array list for easy access public static ArrayList list = new ArrayList() {{ add(INT_ARRAY_1000); add(INT_ARRAY_10000); add(INT_ARRAY_100000); add(INT_ARRAY_1000000); add(INT_ARRAY_2000000); }}; //Excel workbook used for reporting public XSSFWorkbook report; //Start time for a sort public static long startTime; //End time for a sort public static long endTime; //The calculated elapsed time public static long duration; /** * Creates the excel workbook if one does not exist or gets the workbook. * @throws IOException */ public RunSortingAlgorithms() throws IOException { //If the report file does not exist it will be created. if(! Files.exists(new File("report.xlsx").toPath())) { this.report = new XSSFWorkbook(); report.createSheet("Summary"); report.createSheet("Bubble Sort"); report.createSheet("Selection Sort"); report.createSheet("Insertion Sort"); report.createSheet("Quick Sort"); report.createSheet("Merge Sort"); } else { //Otherwise get the file and write data to it. this.report = new XSSFWorkbook(new FileInputStream(new File("report.xlsx"))); } } public void runBubbleSort() throws FileNotFoundException { //What row the info is being placed in. int rowNumber = 1; //What column the info is being placed in int columnNumber; Row row; writeSheet("Bubble Sort"); Sheet sheet = report.getSheet("Bubble Sort"); //Run the sort 10 times for each set of arrays for (int i = 0; i < 10; i++) { //For each array run the sort for (int k = 0; k < 3; k++) { //Get the next array int[] array = list.get(k); //Load it with a new set of the correct number of integers for (int j = 0; j
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote