Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 10: Recursion
Start Practice TestPractice Test
About Exam
hard

Recursive Power Function Complexity

Mark
< Prev
Next >

What is the time complexity of the following recursive power method with respect to the parameter exp?

public int power(int base, int exp) {
    if(exp == 0) return 1;
    int half = power(base, exp / 2);
    if(exp % 2 == 0) {
        return half * half;
    } else {
        return base * half * half;
    }
}
A

O(log n)

B

O(n log n)

C

O(2^n)

D

O(n)

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.

AI Tutor

How can I help?

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