Answered step by step
Verified Expert Solution
Link Copied!

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
a[k++] = l[i++];
while(j
a[k++] = r[j++];
}
}
image text in transcribed
(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

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions