| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice Test
Share
medium Solved by 6 students
Recursive Method Time Complexity
< Prev
Next >

What is the worst-case time complexity of the tail-recursive tailSum method shown below?

public int tailSum(int[] arr, int index, int acc) {
    if(index == arr.length) return acc;
    return tailSum(arr, index + 1, acc + arr[index]);
}
A

O(n)

B

O(log n)

C

O(n^2)

D

O(1)

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1singhris00011 0m 23s 77
#2ethan13 1m 52s -32
#3suhanakochhar00614 6m 22s -312
#4richa.tuli12 9m 10s -460
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy