I am trying to come up with a recurrence relation for the number of multiplications needed for this algorithm:
EXP(x,e):
if e = 0, return 1
else
r = EXP(x, floor(e/2))
if e is even
return r*r
else
return r*r*x
I have calculated the number of multiplications needed for some values of e:
e = 0, 0 multiplications
e = 1, 2 multiplications
e = 2, 5 multiplications
e = 3, 6 multiplications
e = 4, 7 multiplications
e = 5, 12 multiplications
e = 6, 13 multiplications
e = 7, 14 multiplications
I am unable to find a pattern for them. I was trying, for example, to find a recurrence relation starting as $T(n) = 2*T(\frac{n}{2}) + (abc)$ but am unable to find a common (abc).
One thing I have noticed, but don't think leads anywhere, is that if you look at e=2,3,4 you have T(n) = T(n-1) + 1 for those, same thing for e=5,6,7. But obviously that doesn't work for the jump between e=4 and e=5.
Could anyone provide some help/hints?
Thank you.