给定代码的时间复杂度是多少? [英] What is the time complexity of given code?
本文介绍了给定代码的时间复杂度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
While(n>1)
{
n=n/20;
n=n/10;
}
我尝试过这样=>
在这里,n = n / 200
,这意味着N每次都会减少200倍。
因此,时间复杂度= O(log以200为基础)
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)
推荐答案
是的,每次循环中n都会减少到1/200。
Yes, n gets reduced to 1/200 each time in the loop.
因此,此循环将运行log 200 n次。
So, this loop would run log 200 n times.
因此,时间复杂度= O(日志 200 n)。
Hence, time-complexity = O(log 200 n).
这篇关于给定代码的时间复杂度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文