Question: task 3 java lang Task 3. Linear and Binary search. (20 points) Write methods that implement linear and binary search. Whether you use an iterative

Task 3. Linear and Binary search. (20 points) 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 retum 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: 5 10 17 ? 3888 n, where 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 ie iterations to find 10. Linear search needed 17 iterations to find 17. Linear search needed me iterations to find 20. Linear search needed 25 iterations to find 25. Linear search needed 50 iterations to find se. 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 binary Search needed 4 iterations to find 5. binary Search needed 7 iterations to find 10. binarySearch needed 4 iterations to find 17. binary Search needed 5 iterations to find 20. binary Search needed 6 Iterations to find 25. binary Search 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 Edipse to view all the program output CIS 143 - Winter 2021 Lob 4 Page 4 of 5 Rubric: Student name and today's date are a comment on the first line of the program (-5 if fails) linear Search 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 Please paste a screenshot of a successful program run, and copy-and-paste the source code from your main program's.java file, here. 7
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
