| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice TestPractice Test
About Exam
hard Solved by 8 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

I only

B

II only

C

I and II only

D

III only

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
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