-
public static long linearSearch(int[] listOfNumbers, int target);
Input Parameter: int[] listOfNumber - An array of int's.
Input Parameter: int target - The int to be searched for in listOfNumbers.
Method Returns: a long value containing the number of nano-seconds it took to
find specified target within the listOfNumbers. If the
target is not found, the method returns a -1.
-
public static long binarySearch(int[] listOfNumbers, int target);
Input Parameter: int[] listOfNumber - An array of int's.
Input Parameter: int target - The int to be searched for in listOfNumbers.
Method Returns: a long value containing the number of nano-seconds it took to
find specified target within the listOfNumbers. If the
target is not found, the method returns a -1.
int
's (1 to 10,000,000) and search for the following
targets:
-
public static int[] getListOfNumbers();
Method Returns: A sorted array of 10,000,000 int values (1 to 10,000,000). If the array
was not already initialized the first time the method is called, the method must create, initialize
and save the array in a static, private variable within the class. On subsequent calls, the method
should return a reference to the variable already created during the first call.
-
public static void runLinearSearch(int[] listOfNumbers, int target);
Input Parameter: int[] listOfNumber - An array of int's.
Input Parameter: int target - The int to be searched for in listOfNumbers.
This method with call the linearSearch method of the Search class 10 times. It
will save the run time of each call into a static, private array variable that
can be obtained by the getRunTimes() method specified below.
-
public static void runBinarySearch(int[] listOfNumbers, int target);
Input Parameter: int[] listOfNumber - An array of int's.
Input Parameter: int target - The int to be searched for in listOfNumbers.
This method with call the binarySearch method of the Search class 10 times. It
will save the run time of each call into a static, private array variable that
can be obtained by the getRunTimes() method specified below.
-
public static int[] getTargets();
Method Returns: An array of int values containing the targets specified above.
-
public static long[] getRunTimes();
Method Returns: The array of long values containing the run times from the previous test
case.
-
public static void clearRunTimes();
This method will clear the run times to all zero.
-
public static void main(String[] args);
This method will be where you run both the linear and binary searches on all the targets
and print out the run times for each target in a table format.
Please submit the completed assignment on the
Mimir Platform Website
.
You must submit your Java programs as a zip file of only the classes specified above.