Question
Computer Science - Java Help Here's the assignment description: My code won't run....it has bugs. Please fix code and do #3. I can't attach the
Computer Science - Java Help
Here's the assignment description:
My code won't run....it has bugs. Please fix code and do #3. I can't attach the txt files, but there are 7 txt files each with random numbers to be sorted using merge sort and insertion sort. Please follow assignment and give formatted code. Thanks
Code that won't run:
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class mergeSort { public static void main(String args[]) throws FileNotFoundException { int arr[],temp[]; String Filename[] = new String[]{"input_100.txt" , "input_1000.txt","input_5000.txt","input_10000.txt","input_50000.txt","input_100000.txt", "input_500000.txt"}; //Save filenames in a variable double times[] = new double [Filename.length]; int file1=0,file2=0,file3=0,file4=0,file5=0,file6=0,file7=0; Scanner number; for (int n = 0; n high then the array will be sorted else sort the array int mid=low+(high-low)/2;//calculate mid index to break the array into two halves merge_sorting(arr,temp,low,mid);//calling sorting function to sort the left subarray merge_sorting(arr,temp,mid+1,high);//calling sorting function to sort the right subarray merge(arr,temp,low,mid,high);//calling function to merge two subarrays } } public static void merge(int arr[],int temp[],int low,int m, int high){//merging function for(int i=0;ihigh then the array will be sorted else sort the array int mid=low+(high-low)/2;//calculate mid index to break the array into two halves merge_sorting(arr,temp,low,mid);//calling sorting function to sort the left subarray merge_sorting(arr,temp,mid+1,high);//calling sorting function to sort the right subarray merge(arr,temp,low,mid,high);//calling function to merge two subarrays } } */ /* public static void merge(int ar[],int temp[],int low,int m, int high){//merging function for(int i=0;i -1) && ( array [i] > key ) ) { array [i+1] = array [i]; i--; } array[i+1] = key; //the first element is given the smallest value } } }
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class mergeSort { public static void main(String args[]) throws FileNotFoundException { int arr[],temp[]; String Filename[] = new String[]{"input_100.txt" , "input_1000.txt","input_5000.txt","input_10000.txt","input_50000.txt","input_100000.txt", "input_500000.txt"}; //Save filenames in a variable double times[] = new double [Filename.length]; int file1=0,file2=0,file3=0,file4=0,file5=0,file6=0,file7=0; Scanner number; for (int n = 0; n high then the array will be sorted else sort the array int mid=low+(high-low)/2;//calculate mid index to break the array into two halves merge_sorting(arr,temp,low,mid);//calling sorting function to sort the left subarray merge_sorting(arr,temp,mid+1,high);//calling sorting function to sort the right subarray merge(arr,temp,low,mid,high);//calling function to merge two subarrays } } public static void merge(int arr[],int temp[],int low,int m, int high){//merging function for(int i=0;ihigh then the array will be sorted else sort the array int mid=low+(high-low)/2;//calculate mid index to break the array into two halves merge_sorting(arr,temp,low,mid);//calling sorting function to sort the left subarray merge_sorting(arr,temp,mid+1,high);//calling sorting function to sort the right subarray merge(arr,temp,low,mid,high);//calling function to merge two subarrays } } */ /* public static void merge(int ar[],int temp[],int low,int m, int high){//merging function for(int i=0;i -1) && ( array [i] > key ) ) { array [i+1] = array [i]; i--; } array[i+1] = key; //the first element is given the smallest value } } }
Implement a method to sort a given array using the merge sort algorithm. Use the algorithm provided (see Page 2) instead of the algorithm from the te Write a driver program to test the merge sort algorithm for arrays of varying lengths provided in Canvas. Compare the execution time of merge sort with insertion sort implemented in Lab-2. Make sure you use the same array to compare the performance. Use a table or plot to summarize the results and document your observations and analysis in the report. Based on the performance results obtained in Problem-3, modify the merge sort algorithm such that when the array size gets small enough, you would invoke insertion sort instead of invoking merge sort (hint: you have to change the base condition in the recursion). Instead of hardcoding the array size make it a variable that you can pass as an argument to the merge sort method and test this cutoff value with at least four different values Test the program for the same array sizes and values. Compare the performance with the original merge sort implementation, plot the execution times, and document the analysis irn your lab reportStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started