Question
If there are multiple occurences of the target item in an array, what can you say about the subscript value that will be returned by
If there are multiple occurences of the target item in an array, what can you say about the subscript value that will be returned by linearSearch? How many elements will be compared to target for an unsuccessful linear search in an array of 1000 items? What is the answer for 2000 items? Please use comments
/** Recursive linear search method (in RecursiveMethods.java).
@param items The array being search
@param target The item being searched for
@param posFIrst The position of the current first element
@return The subscript of target if found; otherwise - 1
*/
private static int linearSearch(Object[] items, Object target, int posFirst) {
if (posFirst == items.length)
return -1;
else if (target.equals(items[posFirst]))
return posFirst;
else
return linearSearch(items, target, posFirst + 1);
Step 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