What is the time complexity of following nested dependent loops

Khushit Shah
for(int i = 2; i < N; i ++)
    for(int j = 1; j < N; j = j * i)
        sum += 1

I got

time complexity

Can we generalize it further?

kaya3

Using an algebraic identity about logarithms, logᵢ(N) = log N/log i, so we can take log N out as a factor and the summation is then of 1/log i. Approximating this summation as the integral of 1/log x, we get that asymptotically it is O(N/log N), per Wikipedia. Since we previously took out a factor of log N, multiplying by this gives a final result of O(N).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related