Write a Java program that implements both Linear Search and Binary Search. The program willtake a collection of objects (generic type data) as input and print the number of comparisons neededto find a target element within that collection.You will create the following two Java classes:1. SearchCombo.java : Code for both linearSearch and binarySearch will be in this class. Youmay take help from the textbook Chapter 9, Section 9.1. However, note that the design require-ments are different from the textbook code.•Both search methods must use the Comparable interface and the compareTo() method.•Your program must be able to handle different data types, i.e., use generics.•For binarySearch, if you decide to use a midpoint computation formula that is different fromthe textbook, explain that formula briefly as a comment within your code.2. Tester.java : This class will contain the main() method. The user will be asked to enter thecollection of elements (comma or space can be used to separate the elements). The output willbe the number of comparisons the two searching techniques require.Review the sample output given below to get an idea of what the program output should look like.Extracted text: Enter the elements (search pool): 1 12 18 22 31 34 40 46 59 67 85 Target: 40 # of comparisons for Linear Search: 4 # of comparisons for Binary Search: 2 Enter the elements (search pool): 1 12 18 22 31 34 40 46 59 67 85 Target: 100 Not found! # of comparisons for Linear Search: 8 Not found! # of comparisons for Binary Search: 5
Extracted text: Enter the elements (search pool): 1 12 18 22 31 34 40 46 59 67 85 Target: 40 # of comparisons for Linear Search: 4 # of comparisons for Binary Search: 2 Enter the elements (search pool): 1 12 18 22 31 34 40 46 59 67 85 Target: 100 Not found! # of comparisons for Linear Search: 8 Not found! # of comparisons for Binary Search: 5
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here