Recursive Search Missing Base Case
Consider the following methods, which are part of a class. Assume the data array has been initialized with a length greater than 0.
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);
}
}
In which of the following cases will a call to seqSearchRec(5) always cause a runtime error?
I. The data array contains only one element.
II. The data array does not contain the value 5.
III. The data array contains multiple instances of the value 5.
A
I only
B
II only
C
I and II only
D
III only
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | ethan | 2 | 2 | 0m 00s | 200 |
| #2 | singhris000 | 1 | 2 | 1m 35s | -5 |
| #3 | richa.tuli | 3 | 5 | 10m 50s | -370 |
Items per page:
10
1 – 3 of 3
APFIVE