Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Time complexity 查找执行k+;的时间复杂性循环中的sqrt(k)_Time Complexity_Complexity Theory - Fatal编程技术网

Time complexity 查找执行k+;的时间复杂性循环中的sqrt(k)

Time complexity 查找执行k+;的时间复杂性循环中的sqrt(k),time-complexity,complexity-theory,Time Complexity,Complexity Theory,鉴于此代码: intf(intn) { int j=10; while(jC1=-6。这是一个有趣的方法,你有没有其他方法,通常不是用来解决这个问题,而是用来解决像this@aliberro这是另一个更广泛的问题。如果你有其他类似的任务,那么发布它,我们将看看我们能做些什么。

鉴于此代码:

intf(intn)
{
int j=10;
while(j
我如何找到它的时间复杂性,解决方案是
O(sqrt(n))
,但仍然是为什么


感谢您的时间显然,计算
k+1
-th值的
j
可以表示为函数
f(k+1)

(一)

然后,
f(k+1)
可以通过
f(k)
使用以下公式进行近似:

(二)

因此,将(2)放入(1)

现在,一旦
f(k)
达到
n
,步骤数如上所述进行计算,对于该近似值,时间复杂度为
O(sqrt(n))

现在,让我们通过k表达fk:

那么,错误有多大意义呢?请注意,下面使用的
f(k+1)
f(k)
f(k+1)
f(k)
的近似值(来自(1)):

我们不希望错误依赖于
k
,因此我们在它旁边设置了一个系数
0
。因此,C0=2

因此,我们的近似值的误差是
0.25


顺便说一下,我们还可以找到一个剩余系数C1。为此,我们可以使用
f(0)=10的初始值。所以,0=2*sqrt(10)+C1->C1=-6。这是一个有趣的方法,你有没有其他方法,通常不是用来解决这个问题,而是用来解决像this@aliberro这是另一个更广泛的问题。如果你有其他类似的任务,那么发布它,我们将看看我们能做些什么。