Here is the pseudo code below:
pow2(a,b,k)
d := a, e := b, s := 1
until e = 0
if e is odd s:=s·d modk
d:=d2 modk
e := ⌊e/2⌋
return s
end
- The number of time the loop runs is: log b(base 2), As this is the number of times b = e can be halved before it is rounded to 0
- The input size of b is log b
- With all this above information my calculation for the time complexity is as follows: O(log(log b)) (base 2) Which when simplified is like O(2^b) I know I am incorrect as this algorithm is meant to be efficient and so the time complexity should be better.
- The actual time complexity of this algorithm is O(n) wrt to the input size of b.
- please explain how the time complexity O(n) can be determined from all the information above.