Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
hard Solved by 5 students

Recursive Search Missing Base Case

< Prev
Next >

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

III only

B

I only

C

II only

D

I and II only

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1ethan22 0m 00s 200
#2singhris00012 1m 35s -5
#3richa.tuli35 10m 50s -370
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|FAQ