What is the time complexity of the following algorithm?
SUMAB (A, B, N)
sum = 0
for j = 1.. N
k = 2
while k<N
sum - sum + A[j] * B[k]
k = k * k
return sum
What is the time complexity of the following algorithm?
SUMAB (A, B, N)
sum = 0
for j = 1.. N
k = 2
while k<N
sum - sum + A[j] * B[k]
k = k * k
return sum
It's $O(n\log \log n)$. You can see this by noting that the inner loop performs $i$ operations where $2^{2^i} = n$.