Garrick
Garrick

Reputation: 689

What is the time complexity of the given code?

While(n>=1)
{
    n=n/20;
    n=n/6;
    n=10×n;
    n=n-10000;
}

I tried like this =>

In this loop, N gets reduced by N/12 - 10000. so, time complexity is O(log N).

Upvotes: 5

Views: 256

Answers (1)

mort
mort

Reputation: 13608

That seems to be correct. If this is an exercise, you should be prepared to argue why O(log_12(N))is O(log(N)).

Upvotes: 6

Related Questions