Menu

[Solved] 5 4 Points Following Code Merge Sort Modified Print Component Array End Merge Call Output Q37269512

5. (4 points) The following code for merge sort has been modified to print out a component of the array at the end of the mer

5. (4 points) The following code for merge sort has been modified to print out a component of the array at the end of the merge call. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Merge [ private static void merge (String[] a, String[] aux, int lo, int mid, int hi) l int i – lo, j – mid; for (int k lo; k < hi; k if (i- mid)t else if (jhi) aux [k] -a [i++] ; else if (alj].compareTo (ali])0) [ else aux[k] -a[i++] // copy back for (int k-lo; k < hi; k++) a [k] – aux[k]; StdOut.print(“M(” +lo+”, “+hi+”) “) for (int k -lo; k < hi; k++) Stdout.print(a[k] + “”); Stdout.printlnO; public static void sort (Stringl] a, Stringl] aux, int lo, int hi) [ if (hi – lo <- 1) return; int mid lo (hi lo) / 2; sort(a, aux, lo, mid); sort(a, aux, mid, hi); merge(a, aux, lo, mid, hi); public static void main(String[] args) l String data- “it”, “was”, “the”, “best”, “of”, “times” StringC] worknew String[data.length]; Merge.sort (data, work,0,data.length); Show transcribed image text 5. (4 points) The following code for merge sort has been modified to print out a component of the array at the end of the merge call. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Merge [ private static void merge (String[] a, String[] aux, int lo, int mid, int hi) l int i – lo, j – mid; for (int k lo; k

Expert Answer


Answer to 5. (4 points) The following code for merge sort has been modified to print out a component of the array at the end of th… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *