When we are doing normal recursion we are multiplying
a* power(a,n-1)
but when we are doing fast power rescursion
we are not multiplying a, we are directly calculating power(a,n/2). Why?
Fast power recursion
We are multiplying a with small_pow when n is only odd, for even value of n we don’t need to do that. as we are returning square of small_pow and in it we are calculating a^(n/2).
For odd:
return a*small_pow(a,n/2)*small_pow(a,n/2)
For even:
return small_pow(a,n/2)*small_pow(a,n/2)
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.