使用猜测/验证方法查找算法的下界
我试图对算法复杂性进行一些猜测,但是每次我尝试使用指数时间进行猜测时,我的猜测/验证方法似乎都会失败。我确信我正在做一些荒谬的错误,我只是自己找不到它。
例如,如果我有递归 T(n) = 2T(n-1) + T(n-2) + 1 ,其中 T(1) = 0 和 T(2 ) = 1。
通过迭代几次并插入值 n=3,4,5,6,7,8...,我们可以观察到,对于 n>=8 的任何值,T(n) > 。 2^n,因此 2^n 不是上限。
所以,知道这些信息后,我尝试猜测 T(n)=O(2^n)
T(n) <= C(2^n)
2T(n-1)+T(n-2)+1 < ;= C(2^n)
2C(2^(n-1))+C(2^(n-2))+1 <= c(2^n)
C(2^n)-C(2 ^n+2^(n-2)) >= 1
C(-2^(n-2)) >= 1
C >= 1/(2^(n-2)) |当n->无穷大,表达式变为零,
这是否意味着我的猜测太高了?然而,我知道事实并非如此。谁能看出我到底在哪里破坏了这个理论?谢谢。
I am trying to work out a few guesses on algorithm complexity, but every time I attempt to guess using an exponential time, my guess/verify method seems to fail. I am sure I am doing something absurdly wrong, I just can't find it myself.
For Example, if I have the recurrence T(n) = 2T(n-1) + T(n-2) + 1 , where T(1) = 0 and T(2) = 1.
By iterating it a few times and plugging the vales n=3,4,5,6,7,8... we can observe that for any value of n>=8, T(n) > 2^n, therefore 2^n is not an upper bound.
So, knowing that information I try to guess that T(n)=O(2^n)
T(n) <= C(2^n)
2T(n-1)+T(n-2)+1 <= C(2^n)
2C(2^(n-1))+C(2^(n-2))+1 <= c(2^n)
C(2^n)-C(2^n+2^(n-2)) >= 1
C(-2^(n-2)) >= 1
C >= 1/(2^(n-2)) | as n-> infinity, the expression goes to zero
Wouldn't this mean that my guess is too high? However, I know that that is not the case. Can anyone see where exactly am I butchering the theory? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从
2T(n-1)+T(n-2)+1 <= C(2^n)
到2C(2^(n-1))+C 的转换(2^(n-2))+1 <= c(2^n)
是错误的。如果
T(n) <= C(2^n)
您可以推断2T(n-1)+T(n-2)+1 <= 2C(2^ (n-1))+C(2^(n-2))+1
但不是2C(2^(n-1))+C(2^(n-2)) +1 <= c(2^n)
。请注意,
2C(2^(n-1))=C(2^n)
,因此它必须是2C(2^(n-1))+C(2^( n-2))+1 >= c(2^n)
。The transition from
2T(n-1)+T(n-2)+1 <= C(2^n)
to2C(2^(n-1))+C(2^(n-2))+1 <= c(2^n)
is wrong.if
T(n) <= C(2^n)
you can infer that2T(n-1)+T(n-2)+1 <= 2C(2^(n-1))+C(2^(n-2))+1
but not that2C(2^(n-1))+C(2^(n-2))+1 <= c(2^n)
.Note that
2C(2^(n-1))=C(2^n)
so it must be that2C(2^(n-1))+C(2^(n-2))+1 >= c(2^n)
.我认为Itay输入后你的代数是正确的,但你对
c >= 1/(2^(n-2))
的理解是错误的。你是对的,因为
n -->无穷大
,然后1/(2^(n-2)) --> 0 。然而,这并不意味着
c --> 0
,表明你的猜测太大了。相反,这表明c >= 0
。因此,c
可以是任何正常数,这意味着您的猜测是严格的。I think your algebra is correct after Itay's input, but your understanding of
c >= 1/(2^(n-2))
is wrong.You're right that as
n --> infinity
, then1/(2^(n-2)) --> 0
. However, that doesn't mean thatc --> 0
, suggesting that your guess is too high. Rather this suggests thatc >= 0
. Therefore,c
can be any positive constant and implies that your guess is tight.