Which method is better - exponentiation by dividing b by 2 each time , or taking b in binary form and then calculating a^b by right shifting b in each iteration ? Both the methods have time complexity O( log b).
Fast exponentiation comparison
which ever you want you will never get TLE using any of these… But performing opeartion on bits is little faster…
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.