I am not getting its working as I dry run run the code the output is not coming correct and also I am not getting flow of code.
Fast exponentation
main priblem is in understanding flow of code
It is same as thought by the mentor
Okay
Assume it to be like this
We need to find 3^5
5 is written as 101 in binary
We traverse over the binary digits of 5 starting from the right, and keep squaring our current answer since every 1 in binary form denotes 2^i .
So our iteration goes like this
ans = 1 initially
- if odd, mutiply ans by y. Drop that bit. call function again and get its square
- if even, call function again and get its square.
Try to dry again, you will understand
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.