Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

Question #2image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is Larmors formula? Explain with a suitable example.

Answered: 1 week ago