Question: 00 6:58 AM MQ 10: Binary Search Started: Jan 21 at 2:57pm Quiz Instructions Question 1 1 pts Consider the following recursive implementation of binary

 00 6:58 AM MQ 10: Binary Search Started: Jan 21 at
2:57pm Quiz Instructions Question 1 1 pts Consider the following recursive implementation

00 6:58 AM MQ 10: Binary Search Started: Jan 21 at 2:57pm Quiz Instructions Question 1 1 pts Consider the following recursive implementation of binary search on a sorted array of ints (a slight variation on the one seen in class): Courses 28 Groups public static int binarySearch(int a, int x, int low, int high) if [Low> high) { Calendar return -1: //xcan't be in an invali d range int index(owhigh)/2 int y at index); if (x y) t Inbox return index; else if (x y) return binarySearch(a, x, low, index- Help else t IIy return binarySearch(a, x, index+1, hi gh): The below code tests binarySearch by creating an array of a million monotonically increasing values (a subsequent value carn differ from its predecessor by 0, 1, or 2). Then, it times searching for 100000 values in that array. We also add up all the indexes where we find what we're looking for along with -1 values when we don't find what we're looking for. Finally, we search for the same values with binarySearch and also add either the found index or 1 if not found. The code below performs this search. You can place it in a main method. k

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!