Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a java program, base on the code provided down below, do the following question. thanks ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Here is the code: import java.util.*; public

This is a java program, base on the code provided down below, do the following question. thanks

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Here is the code:

import java.util.*; public class sort { public static void main(String args[]) { int size = 10000; //change this line to change the size of the array Random random = new Random(); int arr[] = new int[size]; int temp[] = new int[arr.length]; ArrayList list= new ArrayList(); //Repeating the experiment 100 times System.out.println("**************Quick Sort************** "); for(int i=0;i<100;i++) { for(int j=0;j low) { int mid = (low + high) / 2; mergeSort(a, temp, low, mid); mergeSort(a, temp, mid + 1, high); merge(a, temp, low, mid, high); } } static void merge(int[] a, int[] temp, int low, int mid, int high) { int lowP; for(lowP = low; lowP <= high; ++lowP) { temp[lowP] = a[lowP]; } lowP = low; int highP = mid + 1; int aP; for(aP = low; lowP <= mid && highP <= high; ++aP) { if (temp[lowP] <= temp[highP]) { a[aP] = temp[lowP]; ++lowP; } else { a[aP] = temp[highP]; ++highP; } } int i; if (lowP > mid) { for(i = highP; i <= high; ++i) { a[aP] = temp[i]; ++aP; } } else { for(i = lowP; i <= mid; ++i) { a[aP] = temp[i]; ++aP; } } } //insertion sort static void insertionSort(int[] a) { for(int i = 1; i < a.length; ++i) { int currentElement = a[i]; int j; for(j = i - 1; j >= 0 && a[j] > currentElement; --j) { a[j + 1] = a[j]; } a[j + 1] = currentElement; } } //selection sort static void selectionSort(int[] a) { for(int i = 0; i < a.length - 1; ++i) { int currentMin = a[i]; int currentMinIndex = i; for(int j = i + 1; j < a.length; ++j) { if (currentMin > a[j]) { currentMin = a[j]; currentMinIndex = j; } } if (currentMinIndex != i) { a[currentMinIndex] = a[i]; a[i] = currentMin; } } } }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

The Analysis and the Report

Once you have your spreadsheet with the summary results, write a brief report about your work. Questions like these should be in your mind as you think about the experiment and the report: How does the time it takes for each algorithm to run compare to the size of the data set? What are the best case, worst case and average case times for each method for each array length? How does it fit with functions like T = f(n), T= f(n log(n) ) or T= f( n^2)? What does our book tell us about the time efficiency of these algorithms? Based on this, what did you expect the results to look like before running the time trials? How did the results compare with this? Which algorithm was most efficient? Why was this more efficient than the others? You do not need to explicitly answer each of these questions, but they should guide you in considering what the experiment is all about.

Your report should include:

  • a brief description of the topic what is this experiment all about? What do we hope to learn from it? Why is this important?
  • a brief discussion of what you would expect to see in the experiment based on what you know about the sorting techniques before the experiment.
  • a description of your experiment what did you do? What equipment and software did you use? Include the clock speed of your computer, and the specific compiler you used.
  • a presentation of your results such as a table from the second spreadsheet with the summary results. If you can, create an Excel graph or set of graphs (one for each sorting technique) that illustrates your results.
  • a commentary or analysis of results. What does the data show? How does this compare to what you expected? In particular, how do the iterative sorting methods compare to the recursive sorting methods?

You should be able to cut and paste the table with your summary results from Excel into Word for inclusion in your report.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions