Question: In the file Problem 2 . java implement a static method with the signature: ` ` ` public static > int binarySearch ( E [
In the file Problemjava implement a static method with the signature:
public static
int binarySearchE a E x;
This method should then trigger another helper method that searches the array recursively for the value x Your method should return the index of the element if it's found you may assume that each element is unique Return if the element is not found.
Hint: start with the iterative code that I will present in lecture specifically from the file BinarySearchGeneric
Next, create a main method and test your generic binary search in it by completing the next two steps:
Create a string array, sort it with Arrays.sort and find an element in the array by calling your g eneric binary search.
Create an integer array and sort it with Arrays.sort. Next define a variable target that is a sum of two variables in your array. Write an algorithm that finds two indices in the array with values that sum to the target. Your algorithm needs to run in Onlogn time and call the generic binary search method you defined.
Note that for testing your code, we will only change target to a different sum of two variables and rerun your code. Your implementation should still be able to find the right indices.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
