Question: *JAVA* Adapt the following methods to operate on Strings rather than int arrays: class BinarySearch { // binarySearch() // pre: Array A[p..r] is sorted static

*JAVA* Adapt the following methods to operate on Strings rather than int arrays: class BinarySearch { // binarySearch() // pre: Array A[p..r] is sorted static int binarySearch(int[] A, int p, int r, int target){ int q; if(p > r) { return -1; }else{ q = (p+r)/2; if(target == A[q]){ return q; }else if(target < A[q]){ return binarySearch(A, p, q-1, target); }else{ // target > A[q] return binarySearch(A, q+1, r, target); } } } 

public static void mergeSort(int[] A, int p, int r){ int q; if(p < r) { q = (p+r)/2; // System.out.println(p+" "+q+" "+r); mergeSort(A, p, q); mergeSort(A, q+1, r); merge(A, p, q, r); } }

 public static void merge(int[] A, int p, int q, int r){ int n1 = q-p+1; int n2 = r-q; int[] L = new int[n1]; int[] R = new int[n2]; int i, j, k; for(i=0; i                        

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