Recursion

AP Computer Science A· difficulty 4/5

<code>power(a, b)</code> with O(log b) (using even/odd halving) is achieved by

  • A

    if even: power(a<em>a, b/2); if odd: a</em>power(a, b-1)

    check_circle
  • B

    Use Math.pow

  • C

    Always a * power(a, b-1)

  • D

    Recursion always O(b)

Explanation

Fast exponentiation: divide-and-conquer.

Want 10 more like this — adaptive to your weak spots?

Related questions