Introduction
Binary exponentiation (also known as exponentiation by squaring) is a trick which allows to calculate using only multiplications (instead of multiplications required by the naive approach).
The following recursive approach expresses the same idea:
Implementation
Recursive
Iterative
Complexity
- Time complexity:
- Space complexity: