Binary exponentiation (or exponentiation by squaring) is an algorithm that quickly computes a big power a^b in O(log(b)). This tutorial for beginners includes the intuition, examples, and two C++ implementations: recursive and iterative. Check out https://cp-algorithms.com/ for articles on more advanced algorithms.
Subscribe for more educational videos on algorithms, coding interviews and competitive programming.
- Github repository: https://github.com/Errichto/youtube
- Live streams on 2nd YT channel and on Twitch: https://www.youtube.com/errichto2 & https://www.twitch.tv/errichto
- FB and Twitter: https://www.facebook.com/errichto & https://twitter.com/errichto
- Frequently Asked Questions: https://github.com/Errichto/youtube/wiki/FAQ