According to my evaluation ,the overall asymptotic running time of the below algorithm is O(n)
,since x
(number of recursive calls) is 1, and y
( the number of splits) is 2 , and finally z
( the power of amount of work done outside of the recursion call) is 1, hence x<y^{d}, but my answer turned out to be wrong . Why?
FastPower(a,b) :
if b = 1
return a
else
c := a*a
ans := FastPower(c,[b/2])
if b is odd
return a*ans
else return ans
end