Question: this is my merge sort code using java: public class MergeSort { public void mergeSort(int[] a, int n){ if(n return; int mid = n/2; int[]

this is my merge sort code using java:
public class MergeSort {
public void mergeSort(int[] a, int n){
if(n
return;
int mid = n/2;
int[] l= new int[mid];
int[] r= new int[n-mid];
for(int i=0; i
l[i] = a[i];
for(int i= mid; i
r[i-mid] = a[i];
mergeSort(l, mid);
mergeSort(r, n-mid);
merge(a,l,r,mid,n-mid);
}
public void merge(int[] a, int[] l, int[] r, int left, int right){
int i=0;
int j=0;
int k=0;
while(i
if(l[i]
a[k++] = l[i++];
else
a[k++] = r[j++];
}
while(i
a[k++] = l[i++];
while(j
a[k++] = r[j++];
}
}
 this is my merge sort code using java: public class MergeSort
(c) Make a copy of your mergesort program and modify it so that instead of recursively sorting the two sub-arrays, it would instead sort the two sub-arrays using insertion sort (let us call this new algorithm hybrid-mergesort) (d) Run hybrid-mergesort on the worst-case input for the same value of n that you recorded in part (b) of this exercise. Is the running-time of hybrid-mergesort better or worse than mergesort at this value of n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!