Recursive Search Missing Base Case
For which of the following test cases will the call seqSearchRec(5) always result in an error?
Consider the following instance variable and methods. You may assume that data has been initialized with length>0. The methods are intended to return the index of an array element equal to target, or -1 if no such element exists.
private int[] data;
public int seqSearchRec(int target)
{
return seqSearchRecHelper(target, data.length - 1);
}
private int seqSearchRecHelper(int target, int last)
{
if (data[last] == target)
return last;
else
return seqSearchRecHelper(target, last - 1);
}
For which of the following test cases will the call seqSearchRec(5) always result in an error?
I. data only contains one element
II. data does not contain the value 5
III. data contains the value 5 multiple times
A
II only
B
I only
C
III only
D
I and II only
APFIVE