What is the time complexity of given code?

2019-09-21 02:21发布

问题:

While(n>1)
{
    n=n/20;
    n=n/10;
}

I tried like this =>

Here, n = n/200 which means that N is getting reduced each time by a factor of 200. so, time complexity = O(log base 200 N)

回答1:

Yes, n gets reduced to 1/200 each time in the loop.

So, this loop would run log 200 n times.

Hence, time-complexity = O(log 200 n).