Recursion · routine
Fast power
Write power(x, n) returning x to the power n (a whole number n >= 0) with recursion — without ** or pow.
x^n is (x^(n/2))² when n is even: one recursive call halves the problem.
- right answers
- arguments left as they should be
- fast enough at scale
- without pow
Run adds print(power(2, 10)) after your code, to try it.
Stuck on the idea rather than the code? The Recursion that halves, and recursion that branches lesson walks through it.