What is the time complexity of given code?

你。 提交于 2019-12-13 07:53:20

问题


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).



来源:https://stackoverflow.com/questions/39324836/what-is-the-time-complexity-of-given-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!