Question: java code please details please reference- import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; import static java.lang.System.out; public class
import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; import static java.lang.System.out; public class Words { public static void main(String[] args) throws Exception { Scanner dictionaryScanner = new Scanner(( new URL("https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt").openStream())); List dictionary = new ArrayList(); while (dictionaryScanner.hasNext()) dictionary.add(dictionaryScanner.nextLine()); out.println("read " + dictionary.size() + " words..."); Collections.sort(dictionary); Scanner input = new Scanner(System.in); out.print("Enter a word: "); String word = input.nextLine(); // test linear search boolean found = false; long startTime = System.currentTimeMillis(); for (int i = 0; i words, String word) { int high = words.size() - 1; int low = 0; while (high >= low) { int mid = (high + low) / 2; int compareResult = word.compareTo(words.get(mid)); if (compareResult == 0) return true; if (compareResult > 0) low = mid + 1; if (compareResult boolean linearSearch(List items, E searchItem) { for (int i = 0; i
here one more reference
import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; import static java.lang.System.out; public class Words { public static void main(String[] args) throws Exception { Scanner dictionaryScanner = new Scanner(( new URL("https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt").openStream())); List dictionary = new ArrayList(); while (dictionaryScanner.hasNext()) dictionary.add(dictionaryScanner.nextLine()); out.println("read " + dictionary.size() + " words..."); Collections.sort(dictionary); Scanner input = new Scanner(System.in); out.print("Enter a word: "); String word = input.nextLine(); if (linearSearch(dictionary, word)) out.println("Valid word."); else out.println("Invalid word."); } public static boolean linearSearch(List words, String word) { for (String dictionaryWord : words) if (word.equals(dictionaryWord)) return true; return false; } }
Chapter 14 - Linear Search and Binary Search - Assignment Due Wednesday by 11:59pm 'Points 100 Submitting a text entry box or a file upload Attempts 0 Allowed Attempts 1 Available until Mar 1 at 11:59pm Modify the binarySearch method shown in the video lecture so that it's generic. Test it with at least two types to make sure it works. Hint 1: Examine the review problem and its solution, which modifies the linear search algorithm in the same way. Hint 2; Your binarySearch method signature should be: "private static > boolean binarySearch(List
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
