Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4) (10 pts) Merge Sort vs Insertion Sort Running time analysis a) Modify code-Now that you have verified that your code runs correctly using the

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
4) (10 pts) Merge Sort vs Insertion Sort Running time analysis a) Modify code-Now that you have verified that your code runs correctly using the data.txt input file, you can modify the code to collect running time data. Instead of reading arrays from the file data.txt and sorting, you will now generate arrays of size n containing random integer values from 0 to 10,000 to sort. Use the system clock to record the running times of each algorithm for ten different values of n for example: n = 5000, 10000, 15000, 20,000, ..., 50,000. You may need to modify the values of n if an algorithm runs too fast or too slow to collect the running time data (do not collect times over a minute). Output the array size n and time to the terminal. Name these new programs insertTime and mergeTime. Submit a copy of the timing programs to TEACH in the Zip file from problem 3. b) Collect running times - Collect your timing data on the engineering server. You will need at least eight values of t (time) greater than 0. If there is variability in the times between runs of the same algorithm you may want to take the average time of several runs for each value of n. Create a table of running times for each algorithm. c) Plot data and fit a curve - For each algorithm plot the running time data you collected on an individual graph with n on the X-axis and time on the y-axis. You may use Excel, Matlab, R or any other software. What type of curve best fits each data set? Give the equation of the curves that best "fits" the data and draw that curves on the graphs. d) Combine - Plot the data from both algorithms together on a combined graph. If the scales are different you may want to use a log-log plot. e) Comparison - How does your experimental running times compare to the theoretical running times of the algorithms? 10:17 / InsertionSort.java: Java program to sort integers using Insertion sort import java.io.File; import java.io.FileWriter: import java.io.IOException; import java.util.Scanner, public class Insertion Sort Il method to sort the array of integers in ascending order using insertion sort public static void insertion Sortint numArray[ intij.key: // loop from 1 to end of array for i=1;i-0 && numArray[] >key) numArray[+1) = numArray[i]; numArray[i+1] =key; public static void main(String[] args) throws IOException Scanner fileScan = new Scanner(new File("data.txt")) open the input file, provide full path to file FileWriter in Writer = new FileWriter("insert.txt"); // create and open the output file for insertion sort int size: int data); W loop till the end of input file while(fileScan.hasNext) size = (int) (fileScan.nextDouble(); // read the number of integers in the line (may be double, so convertit into int after reading it as double) // create the array of size data-new int[size] 1/ read size number of integers in the line for(int i=0;i

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_2

Step: 3

blur-text-image_3

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

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

A tool which edits images, or a person who edits images

Answered: 1 week ago