Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions