sir i dont understand the working of fast power code (the recursive part i.e. how the controller is handling the process mean how recursion is going on) i understand the basic recursion logic but not this one
Fast power problem
It is very simple. Try to think the recurrance relation in finding the power.
You know that a^b= a x a^(b-1)
So simply the recurrance relation will be given as
f(a,b)=a x f(a,b-1)
Fast power is the optimized version of this:
You can also write
a^b= a^(b/2)^2 when b is even
and a x a^(b/2)^2 when b is odd.
Similarly the recurrance relation here will be:
f(a,b)=f(a,b/2)^2 when b is even
and a x f(a,b/2)^2 when b is odd.
This is a basic recursion problem. Watch the video again if still it is not clear.
i got this thing sir but the thing is how the control flow goes as bhaiya did not dry run the code for fast power