Write a class using ArraySearch<E> that has these two methods: 1. static int fin
ID: 3541999 • Letter: W
Question
Write a class using ArraySearch<E> that has these two methods:
1. static int find (E [] haystack, E needle);
2. static int first_duplicate (E [] data);
The find method searches the haystack array to see if the elements inside are the same, which is determined by the equals method, as the needle. If the search finds a match, find returns the index that belongs to the first match. If not, find throws the exception java.util.MissingResourceException.
The method first_duplicate searches the data array to see if any two different elements of the array are the same (determined by the equals method). The return value is the index of the first duplicate found, or -1 if each of the elements of the array is unique,
**no element of the array is equal to any other element of the array**
You will also have to write code to test your ArraySearch class. Include this test code when you submit your assignment. This test code will not be graded, however.
ALGORITHM ANALYSIS
Write up a short runtime analysis of each of the two methods, giving the big-O for each method and briefly explain how you got your results
Explanation / Answer
private E[] a; @SuppressWarnings({"unchecked"}) public GenSet(Class c, int s) { // Use Array native method to create array of a type only known at run time a = (E[]) Array.newInstance(c,s); } E get(int i) { return a[i]; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.