Question: For your reference only, here is a code for mergesort. public class MergeSort { private static void merge ( Comparable [ ] a , Comparable

For your reference only, here is a code for mergesort.
public class MergeSort{
private static void merge(Comparable[] a, Comparable[] aux, int lo, int mid, int hi)
{
for (int k = lo; k <= hi; k++) aux[k]= a[k];
int i = lo, j = mid+1;
for (int k = lo; k <= hi; k++)
{
if (i > mid) a[k]= aux[j++];
else if (j > hi) a[k]= aux[i++];
else if (less(aux[j], aux[i])) a[k]= aux[j++];
else a[k]= aux[i++];
}
}
private static void sort(Comparable[] a, Comparable[] aux, int lo, int hi){
if (hi <= lo) return;
int mid = lo +(hi - lo)/2;
sort(a, aux, lo, mid);
sort(a, aux, mid+1, hi);
merge(a, aux, lo, mid, hi);
/*** array inspected here ***/
}
public static void sort(Comparable[] a)
{
Comparable[] aux = new Comparable[a.length];
sort(a, aux, 0, a.length -1);
}
}
The input array is:
01234567927860493730183
At the end of a certain recursive call of method sort(), line with "/***...***/", the array looks like this:
01234567496078923037318
How many calls to method merge() have been completed?

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 Programming Questions!