Question: For this assignment you are to write a Java class that has no main method. The name of the class must be LinearBinarySearch. This class

For this assignment you are to write a Java class that has no main method. The name of the class must be LinearBinarySearch. This class will contain two methods. The signatures for these two methods are shown below:

 public static int linearSearch(int[] arr, int key) 
 public static int binarySearch(int[] arr, int key) 

Both methods search the given array looking for the location of the given key. If the key is in the array, both methods return the index where the key is located. If the key is not in the array, then a negative value is returned, as follows:

Linear Search always returns the value of -1 if the key is not in the array. Binary Search returns (-low 1) if the key is not in the array, where low is the variable used in the Binary Search algorithm. This allows the insertion point for the key to be determined.

For this assignment you are provided with a tester program. If your class is correct, the tester program will print a message indicating that all tests were passed, otherwise, an error message will be displayed.

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!