Question
Searcher.java import java.lang.UnsupportedOperationException; import java.util.Scanner; public class Searcher { public static final int LINEAR_SEARCH_OPTION = 0; public static final int BINARY_SEARCH_OPTION = 1; public static
Searcher.java
import java.lang.UnsupportedOperationException; import java.util.Scanner;
public class Searcher { public static final int LINEAR_SEARCH_OPTION = 0; public static final int BINARY_SEARCH_OPTION = 1; public static void main(String[] args) { Scanner sc = new Scanner(System.in); // parse the search method int searchMethod = Integer.parseInt(sc.nextLine()); // parse the number to find int n = Integer.parseInt(sc.nextLine()); // parse the list of numbers to search in String[] numberStrings = sc.nextLine().split(" "); int[] numbers = new int[numberStrings.length]; for (int i = 0; i
Fill in the starter code, and include comments(beginner here)
Code using java
In this problem, the first line of input represents the type of search used where 0 will indicate linear search and 1 will indicate binary search. The second line will represent an integer to find in a list. The third line will represent a space-separated list of numbers to search through. The output is a single line stating true if the integer is contained in the given list of numbers or false if it is not. For example, the following input should produce an output of true: 4 0 1 3 7 8 1000000 4 5 (a) (3 points) In the file Searcher.java, implement the linearSearch() method. This method should perform linear search on the given input list, and return true iff (if and only if) the desired integer is in the list (b) (3 points) In the file Searcher.java, implement the binarySearch() method. This method should perform binary search on the given input list, and return true iff (if and only if) the desired integer is in the list. You may assume the list is sortedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started