Question: ICS assignment please help~~ I need to code also the algorithem analysis, thank you so much Searching in an array Write a class, ArraySearch that
ICS assignment please help~~ I need to code also the algorithem analysis, thank you so much
Searching in an array
Write a class, ArraySearch
int find_for (E [] haystack, E needle);
int find_other (E [] haystack, E needle);
int first_duplicate (E [] data);
The two find methods search the haystack array to see if any of its elements is the same (as determined by the equalsmethod) as the needle. If there is a match, find returns the index of the first match. Otherwise, find throws the exception java.util.MissingResourceException.
find_for must be implemented using a for loop. find_other must be implemented using methods from the Java standard library, so that your code for find_other has no explicit loops.
The method first_duplicate searches the data array to see if any two different elements of the array are the same, again as 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, i.e., 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 with your submission. This test code will not be graded, but it may help the TA give you better feedback.
Algorithm Analysis
Write up a runtime analysis of each of the three methods, giving the big-O of each, and explaining how you got your results. Since you don't know how the Java standard library functions are implemented, make reasonable assumptions and include the assumptions with your analysis (if the assumptions are unreasonably, your score for the assignment may be affected).
You should use the timing code in Loops.java to verify that your code behaves as expected.
Send your analysis to the TA together with your code. This part counts for 25% of the grade on this assignment. Even if your code doesn't work, you should do this part to the best of your ability.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
