What will be the time complexity of the following code?
for(i=0;i<=n;i++)
for(j=0;j<=log i;j++)
print("hello world");
What will be the time complexity of the following code?
for(i=0;i<=n;i++)
for(j=0;j<=log i;j++)
print("hello world");
Summing up the number of times the inner loop is iterating, we get,
log1 + log2 + log3 + log4 + ... + logN
= log(N!)
And according to Stirling's approximation, log(N!) = O(N x log(N))
So the time complexity is O(NlogN)