Question: Question #1 Question #2 Write an algorithm that takes an ArrayList and uses a recursive binary search to return both the index of a given

Question #1

Question #1 Question #2 Write an algorithm that takes an ArrayList and

Question #2uses a recursive binary search to return both the index of a

Write an algorithm that takes an ArrayList and uses a recursive binary search to return both the index of a given String, or -1 if the String does not exist in the ArrayList. Then, have it also return the number of recursions needed to search. The two numbers should be returned as a String in the format". Input ArrayLists are already sorted in alphabetical order. NEEDS TESTING, TEST CASE FINALIZING, FEEDBACK OVERWRITING 1 public String binSearch(ArrayList list, String target) { 2 int low = 0; 3. int high = list.size()-1; return binSearch(list, target, low, high, ); vou 6 public String binSearch(ArrayList list, String target, int low, int high, int recursions) { Complete the following binary search method. Find the number num in the array array. Return -1 if the number not found. You may assume the array is properly ordered. Examples: binarySearch({1,4,7},7) -> 2 binarySearch({2,6,6,8,80},6) -> 2 1 public int binarySearch(int[]array, int num) { 2 int low = 0; // low range int high = array.length -1; //high range int mid; //mid range while () //while Low is less than or equal to high mid = ; //set middle range to be (low + high) 721 if () { //if the array in the middle range = input number //return mid range else if () { //if the array in the middle range > input number // set the high value to be the mid value minus 1 else // set low value to be mid value plus one 24 //return -1 here because that would mean that the number is not found in the Loop 25 }

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!