Question: Objectives Implement an iterative version of the linear and binary search algorithms Display a tabular trace of a linear and binary search Description For this



Objectives Implement an iterative version of the linear and binary search algorithms Display a tabular trace of a linear and binary search Description For this activity you will implement linear and binary search algorithms. There is a test class (TestSearchMethods.java) in the starter code that you can use to test your search methods. When you are successful, your output should match the output below. Rather than implement the recursive version of binary search show on page 171 of your textbook (3rd edition), implement an iterative version. That means you will need to use a while or for loop ( recommend a while loop in this case). To get your output spaced neatly like what you see below, use tab characters when you print the output. You can see an example of this (along with the use of printf, although printf isn't required for this assignment) in the starter code. Sample Output (TestSearchMethods.java) Test Array 2 4 9 19 32 43 59 60 78 99 Linear search for 43 Index a[1] return 0 2 1 4 2 9 3 19 4 32 5 5 Found 43 at index 5 Comparisons - 6 Linear search Eor 80 Index a[1] return 0 2 1 4. 9 2 3 19 4 32 5 43 6 59 7 60 8 9 99 Not found Comparisons 78 = 10 Binary search for 9 first last mid 0 9 4 0 3 2 3 Found 9 at index 2 Comparisons = 3 a (mid] return 32 4 9 2 NIIR NP Binary search for 80 first last mid 0 9 4 5 9 7 8 9 9 9 9 Not found Comparisons a (mid) return 32 60 78 99 public class TestSearchMethods 3 { 4 public static void main(String[] args) { int al] = {2, 4, 9, 19, 32, 43, 59, 60, 78, 99}; 7 8 System.out.println("Test Array"); for (int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
