Mayank
Mayank

Reputation: 11

What will be the time complexity for this piece of code?

int p=0;
for(int i=0;i<n;i=i*2)
{
    p++;
}
for(int j=0;j<p;j=j*2)
{
    //statements
}

I am getting the time function to be log(N) + log(log(N)). My main question is whether the Time Complexity in this case would be O(logN) or O(log(logN)).

Upvotes: 1

Views: 38

Answers (1)

Mureinik
Mureinik

Reputation: 311103

O(log(log(N)) is negligible compared to O(log(N)), so you can say the overall time complexity is O(log(N)).

Upvotes: 3

Related Questions