Question: For JAVA Write methods that implement linear and binary search. Whether you use an iterative or recursive solution is up to you, but an iterative
For JAVA


Write methods that implement linear and binary search. Whether you use an iterative or recursive solution is up to you, but an iterative solution may be easier for this problem. Have both methods display the value searched for, and the number of iterations needed to find the value. You will need to add System.out.println( ) statements just before both return statements for each algorithm. You will also need to add some kind of counter to track iterations. To test this, create an array: (0,1,2,3,4,5,6,7,8,) of at least 100 values. Search for the following values in the array, first using linear search, then using binary search. Values: 5101720255083 n, where n is the length of the array. (If the array has 100 values, search for the number 100 .) 1 Your program output could look like: Testing search with an array of length 100 Testing linear search: Linear search needed 5 iterations to find 5. Linear search needed 10 iterations to find 10. Linear search needed 17 iterations to find 17. Linear search needed 20 iterations to find 20. Linear search needed 25 iterations to find 25 . Linear search needed 50 iterations to find 50. Linear search needed 83 iterations to find 83. Linear search needed 100 iterations and FAILED to find 100. Linear search needed 100 iterations and FAILED to find 1. Testing binary search: binarySearch needed 4 iterations to find 5. binarySearch needed 7 iterations to find 10. binarySearch needed 4 iterations to find 17. binarySearch needed 5 iterations to find 20 . binarySearch needed 6 iterations to find 25 . binarySearch needed 6 iterations to find 50. binarysearch needed 5 iterations to find 83 . binarySearch needed 7 iterations and FAILED to find 100. binarySearch needed 6 iterations and FAILED to find 1. You will need to resize the console window in Eclipse to view all the program output. - Rubric: - linearSearch and binarySearch implemented correctly: (-10 if fails) - Screenshot shows all program output: (-8 if fails) - Recursive binary search with iteration tracker: +5 bonus - Iteration counter, linear search: 5 points - Iteration counter, binary search: 5 points - Array of at least 100 values: 3 points - Test cases: 5 points - Program output: 2 points
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
