| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice TestPractice Test
About Exam
easy
Recursive Linear Search
< Prev
Next >

Given the array {3, 7, 9, 5, 9}, what index is returned by findPosition when searching for the value 9 starting at index 0?

public int findPosition(int nums[], int key, int currentIndex) {
    if(currentIndex >= nums.length)
       return -1;
    if(nums[currentIndex] == key)
       return currentIndex;
    return findPosition(nums, key, currentIndex + 1);
}

// In main:
// int[] players = {3, 7, 9, 5, 9};
// System.out.println(findPosition(players, 9, 0));
A

0

B

2

C

-1

D

4

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

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy