Question

COMPLETE BigMerge public class BigMerge {       /*    * Returns j such that a[j][index[j]]...

COMPLETE BigMerge

public class BigMerge {
  
   /*
   * Returns j such that a[j][index[j]] is the minimum
   * of the set S={a[i][index[i]] for every i such that index[i]<a[i].length}
   * If the set S is empty, returns -1
   * Runs in time a.length.
   *
   * NOTE: normally this would be private, but leave it
   * public so we can test it separately from your merge.
   */
   public static int argMin(int [][] a, int [] index) {
       // TODO: Implement this using a similar method to
       // how we find the minimum in, for example, selection sort.
       // Watch out for the case when index[i]==a[i].length
       // Implement this before you try to implement merge
// FYI: in our version, this takes up 13 lines of code

       return -1; // just a place holder for now, so compiler doesn't complain
   }
  
   /*
   * Assumes a[0]...a[length-1] each is sorted in increasing order
   * Returns a single sorted array containing all the elements in a
   * Does not modify a.
   * Runs in time k^2 * n, where k is a.length and n is the
   * total number of integers in a.
   */
   public static int [] merge (int [] [] a) {
       // TODO: implement.
       // Suggestions: calculate the length of returned array ret
       // and create ret.
       // Maintain an array called index of length a.length
       // that has your current index into each of the arrays of a
       // (that is, you have a.length indices instead of just
       // the two indices maintained merge in mergeSort)
       // At each iteration, use the argMin method implemented above
       // to decide which element gets to move into ret.
// FYI: in our version, this takes up 12 lines of code

       int [] ret={}; // just a placeholder -- change as needed
       return ret; // just a placeholder -- change as needed
   }
}

(Below Code is completed and it is used to test if BigMerge.java is compiling well.)

public class DriverForBigMerge {
   public static void testBigMerge() {
       int [][] a = {{0,5,10,15,20},{1,6,11},{12},{3,8,13,18,23,28}};
       for (int x: BigMerge.merge(a)) System.out.println(x+" ");
   }
  
   public static void main(String[] args) {
       testBigMerge();
  
   }      
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Soluon Publie claw Bigherge bookan all used 근 true o Int ao; ic inder lent, i forno ;ica.lergth; i+) j-i reak forChD 120; icapublic static mt C ว merre linttula) for Cint iso; ka lnglh; int next SmallestニQr8Nin(a, inder丿ノ beok retun ret

Add a comment
Know the answer?
Add Answer to:
COMPLETE BigMerge public class BigMerge {       /*    * Returns j such that a[j][index[j]]...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • public class SelectionSorter { //Returns the index of the largest element in the arrayOfIntegers, beginning from...

    public class SelectionSorter { //Returns the index of the largest element in the arrayOfIntegers, beginning from the fromIndex. public static Integer[] selectSort(Integer[] incoming) {        Integer[] ret = new Integer[incoming.length]; for (int i = 0; i < incoming.length; i++) {            ret[i] = incoming[i];        }        int temp = 0;        for (int i = 0; i < ret.length - 1; i++) {            if (ret[i] > ret[i + 1]) {...

  • Please merge all the codes below and add comments using JAVA Program. I need a complete...

    Please merge all the codes below and add comments using JAVA Program. I need a complete code which is the combination of the following codes: // Merges the left/right elements into a sorted result. // Precondition: left/right are sorted public static void merge(int[] result, int[] left,                                        int[] right) {     int i1 = 0;   // index into left array     int i2 = 0;   // index into right array     for (int i = 0; i < result.length; i++)...

  • Write merge method for mergeSort method, it takes the array of data, starting index of first...

    Write merge method for mergeSort method, it takes the array of data, starting index of first half, starting index of second half and end index of second half. please use the code below to test it public class A4Sort{ public static void mergeSort(int[] a, int l, int h){ if (l >= h) return; int mid = (h + l) / 2; mergeSort(a, l, mid); mergeSort(a, mid + 1, h); merge(a, l, mid + 1, h); } public static void main(String[]...

  • You will implement the following method public static int[] linearSearchExtended(int[][] numbers, int key) { // Implement...

    You will implement the following method public static int[] linearSearchExtended(int[][] numbers, int key) { // Implement this method return new int[] {}; }    There is a utility method provided for you with the following signature. You may use this method to convert a list of integers into an array. public static int[] convertIntegers(List<Integer> integers) Provided code import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Scanner; public class MatrixSearch { // This method converts a list of integers to an array...

  • must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int...

    must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...

  • USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list...

    USE JAVA PROGRAMMING Create a program that would collect list of persons using double link list and use a Merge Sort to sort the object by age. Create a class called Person : name and age Create methods that add, and delete Person from the link list Create a method that sorts the persons' objects by age. package mergesort; public class MergeSortExample { private static Comparable[] aux; // auxiliary array for merges public static void sort(Comparable[] a) { aux =...

  • Your running times will probably be different than these. Please do a better job with the snipping tool than I did. Jav...

    Your running times will probably be different than these. Please do a better job with the snipping tool than I did. Java program provided: // Student Name Today's Date import java.util.Arrays; import java.util.Random; public class SortTimer {    // Please expand method main() to meet the lab requirements.       // You have the following sorting methods available:    // insertionSort(int[] a);    // selectionSort(int[] a);    // mergeSort(int[] a);    // quickSort(int[] a);    // The array will be in sorted order after the routines are called!   ...

  • In class we wrote a method closestPairFast that on an input array of numbers, finds the...

    In class we wrote a method closestPairFast that on an input array of numbers, finds the distance of the closest pair by first sorting the input array and then finding the closest adjacent pair. (See the file ClosestPair1D.java in the Code folder on D2L.) In this problem, you are asked to modify the method so that it returns an integer array consisting of the indices of the closest pair in the original array. If there is a tie, just return...

  • 6. (4 points) The following code for insertion sort has been modified to print out the...

    6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. 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 Insertion ( public static void sort (String[] a) f int n- a.length; for (int i-1; i < n; i++) f for (int j i; j 0; j--) if...

  • // CMPS 390 // MinHeap.java // Complete 4 methods: getMin, add, removeMin, reheap public class MinHeap...

    // CMPS 390 // MinHeap.java // Complete 4 methods: getMin, add, removeMin, reheap public class MinHeap { private Comparable a heap; // array of heap entries private static final int DEFAULT MAX SIZE = 100; private int lastIndex; // index of last entry public MinHeap() { heap = new Comparable (DEFAULT_MAX_SIZE]; lastIndex = 0; } // end default constructor public MinHeap (int maxSize) { heap = new Comparable (maxSize); lastIndex = 0; } // end constructor public MinHeap (Comparable[] entries)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT