Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
(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 a[k++] = l[i++];
while(j
a[k++] = r[j++];
}
}
Step 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