[英]Asymptotic notations
From what I have studied: I have been asked to determine the complexity of a function with respect to another function. 根据我的研究:我被要求确定一个函数相对于另一个函数的复杂性。 ie Given
f(n)
and g(n)
, determine O(f(n()
. In such cases, I substitute values, compare both of them and arrive at a complexity - using O(), Theta and Omega notations
. 即给定
f(n)
和g(n)
,确定O(f(n()
。在这种情况下,我替换值,比较它们并得到复杂性 - 使用O(), Theta and Omega notations
。
However, in the substitution method for solving recurrences
, every standard document has the following lines: 但是,在
substitution method for solving recurrences
的substitution method for solving recurrences
,每个标准文档都有以下几行:
• [Assume that T(1) = Θ(1).]
• Guess O(n3) . (Prove O and Ω separately.)
•
Guess O(n3) . (Prove O and Ω separately.)
Guess O(n3) . (Prove O and Ω separately.)
• Assume that T(k) ≤ ck3 for k < n .
•
Assume that T(k) ≤ ck3 for k < n .
• Prove T(n) ≤ cn3 by induction.
•
Prove T(n) ≤ cn3 by induction.
How am I supposed to find O and Ω when nothing else (apart from f(n)) is given? 除了f(n)之外,除了f(n)之外,我怎么能找到O和Ω? I might be wrong (I, definitely am), and any information on the above is welcome.
我可能错了(我,绝对是),欢迎提供上述任何信息。
Some of the assumptions above are with reference to this problem: T(n) = 4T(n/2) + n
, while the basic outline of the steps is for all such problems. 上面的一些假设是参考这个问题:
T(n) = 4T(n/2) + n
,而步骤的基本轮廓是针对所有这些问题。
That particular recurrence is solvable via the Master Theorem, but you can get some feedback from the substitution method. 通过主定理可以解决特定的重复,但是您可以从替换方法中获得一些反馈。 Let's try your initial guess of
cn^3
. 让我们尝试你对
cn^3
初步猜测。
T(n) = 4T(n/2) + n
<= 4c(n/2)^3 + n
= cn^3/2 + n
Assuming that we choose c
so that n <= cn^3/2
for all relevant n
, 假设我们选择
c
使所有相关n
n <= cn^3/2
,
T(n) <= cn^3/2 + n
<= cn^3/2 + cn^3/2
= cn^3,
so T
is O(n^3)
. 所以
T
是O(n^3)
。 The interesting part of this derivation is where we used a cubic term to wipe out a linear one. 这个推导的有趣部分是我们使用立方项来消除线性项。 Overkill like that is often a sign that we could guess lower.
这样的矫枉过正常常表明我们可以猜到更低。 Let's try
cn
. 我们来试试
cn
。
T(n) = 4T(n/2) + n
<= 4cn/2 + n
= 2cn + n
This won't work. 这不行。 The gap between the right-hand side and the bound we want is is
cn + n
, which is big Theta of the bound we want. 右边和我们想要的边界之间的差距是
cn + n
,这是我们想要的边界的大Theta。 That usually means we need to guess higher. 这通常意味着我们需要更高的猜测。 Let's try
cn^2
. 我们来试试
cn^2
。
T(n) = 4T(n/2) + n
<= 4c(n/2)^2 + n
= cn^2 + n
At first that looks like a failure as well. 起初看起来也像失败一样。 Unlike our guess of
n
, though, the deficit is little o of the bound itself. 然而,与我们对
n
的猜测不同,赤字本身就是一点点。 We might be able to close it by considering a bound of the form cn^2 - h(n)
, where h
is o(n^2)
. 我们或许可以通过考虑形式
cn^2 - h(n)
的界限来关闭它,其中h
是o(n^2)
。 Why subtraction? 为何减法? If we used
h
as the candidate bound, we'd run a deficit; 如果我们用
h
作为候选界限,我们就会出现赤字; by subtracting h
, we run a surplus. 通过减去
h
,我们运行盈余。 Common choices for h
are lower-order polynomials or log n
. h
常见选择是低阶多项式或log n
。 Let's try cn^2 - n
. 我们试试
cn^2 - n
。
T(n) = 4T(n/2) + n
<= 4(c(n/2)^2 - n/2) + n
= cn^2 - 2n + n
= cn^2 - n
That happens to be the exact solution to the recurrence, which was rather lucky on my part. 这恰好是复发的确切解决方案,这对我来说相当幸运。 If we had guessed
cn^2 - 2n
instead, we would have had a little credit left over. 如果我们已经猜到了
cn^2 - 2n
,我们就会留下一些信用。
T(n) = 4T(n/2) + n
<= 4(c(n/2)^2 - 2n/2) + n
= cn^2 - 4n + n
= cn^2 - 3n,
which is slightly smaller than cn^2 - 2n
. 它略小于
cn^2 - 2n
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.