| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice Test
Share
hard Solved by 5 students
Recursive Search Missing Base Case
< Prev
Next >

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

III only

B

I and II only

C

I only

D

II only

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1ethan22 0m 00s 200
#2singhris00012 1m 35s -5
#3richa.tuli35 10m 50s -370
APFIVE © 2020.
Email: [email protected]|Privacy Policy