简体   繁体   English

二次函数的渐近紧界

[英]asymptotic tight bound for quadratic functions

In CLRS ( Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein), for a function在 CLRS(Cormen、Leiserson、Rivest 和 Stein的算法简介)中,对于 function

f ( n ) = an 2 + bn + c f ( n ) = an 2 + bn + c

they said他们说

Suppose we take the constants c 1 = a /4, c 2 = 7 a /4, and n 0 = 2·max(| b |/ a , √(| c |/ a )).假设我们将常量c 1 = A / 4, c 2 = 7 A / 4,和N 0 a / 4,和N = 2·MAX(| B | B | B | / k / k / k / k / k / k / k / k / k. / k / k / k / k / k / k / k / k / k / k / k / kmax (| b | b
Then 0 ≤ c 1 n 2an 2 + bn + cc 2 n 2 for all nn 0 .那么0c 1 n 2an 2 + bn + cc 0 2 n所有。
Therefore f ( n ) is Θ( n 2 ).因此f ( n ) 是 Θ( n 2 )。

But they didn't specify how values of these constants came?但是他们没有具体说明这些常量的值是如何来的?
I tried to prove it but couldn't.我试图证明它,但不能。
Please tell me how these constants came?请告诉我这些常数是怎么来的?

There's nothing special about those particular constants (other than the fact that in context of a certain n value they will satisfy the theta-ness of f ).这些特定常数没有什么特别之处(除了在某个n值的上下文中它们将满足f的 theta 值的事实)。 No magic.没有魔法。 If you can find other positive constants whereby the relation holds that is just as valid (in fact, c1 can be ka for any 0<k<1 ).如果您可以找到其他正常数,从而使关系成立,那同样有效(实际上,对于任何0<k<1c1都可以是ka )。 Although since they're there, let's analyse c1 :虽然既然他们在那里,让我们分析一下c1

We need it to satisfy the following inequality:我们需要它满足以下不等式:

c1*n^2 <= an^2 + bn + c

Let's take their value: c1 = a/4 .让我们取它们的值: c1 = a/4 For what n can we guarantee that the inequality holds?对于多少n我们可以保证不等式成立? We could solve:我们可以解决:

a/4*n^2 <= an^2 + bn + c
<==> 0 <= 3a/4*n^2 + bn + c

The quadratic has solutions at (-b +- sqrt(b^2-3ac)) / (3a/2) , only the positive of which is of any interest since we have a positive leading coefficient polynomial, so we require n > 2 * (sqrt(b^2-3ac) - b) / 3a which is well defined assuming b^2 >= 3ac (and if not, then the quadratic is positive definite, which is even better, since its >=0 everywhere and the inequality holds for all n).二次方程在(-b +- sqrt(b^2-3ac)) / (3a/2) ,由于我们有一个正的前导系数多项式,因此只有正解是有意义的,所以我们需要n > 2 * (sqrt(b^2-3ac) - b) / 3a假设b^2 >= 3ac是很好定义的(如果不是,那么二次是正定的,这甚至更好,因为它在任何地方 >=0 并且不等式适用于所有 n)。 I should point out that this is a valid solution, although we'll do a bit more work until we arrive at the book's representation.我应该指出这是一个有效的解决方案,尽管我们会做更多的工作,直到我们到达本书的表示。

We can split our analysis into 2 cases.我们可以将分析分为两种情况。 First, let's assume |b|/a >= sqrt(|c|/a) .首先,让我们假设|b|/a >= sqrt(|c|/a) So we can bound from above the inside of the sqrt(...) with 4b^2 , and require n > 2/3 * [sqrt(4b^2)-b]/a which can be upper bounded by 2/3 * 3|b|/a = 2|b|/a .所以我们可以从sqrt(...)的内部上方用4b^2绑定,并且要求n > 2/3 * [sqrt(4b^2)-b]/a上限可以是2/3 * 3|b|/a = 2|b|/a

Second case, let's assume |b|/a < sqrt(|c|/a) .第二种情况,假设|b|/a < sqrt(|c|/a) So we can bound from above the inside of the sqrt(...) with 4a|c|所以我们可以用4a|c|sqrt(...)内部的上方绑定, and require n > 2/3 * [sqrt(4a|c|)-b]/a which can be upper bounded by 2/3 * 3*sqrt(a|c|)/a = 2sqrt(|c|/a) . , 并且要求n > 2/3 * [sqrt(4a|c|)-b]/a上限可以是2/3 * 3*sqrt(a|c|)/a = 2sqrt(|c|/a)

So in each case we see that when we take max(|b|/a, sqrt(|c|/a)) our inequality holds when n > 2 * max所以在每种情况下,我们看到当我们取max(|b|/a, sqrt(|c|/a))时,我们的不等式在n > 2 * max时成立

Similarly for c2 .对于c2也是如此。

The idea is to (for big enough n ) "trap" the function of interest between two "pure" growth functions (that have only a single constant of proportionality).这个想法是(对于足够大的n )在两个“纯”增长函数(只有一个比例常数)之间“捕获”感兴趣的 function。 In this figure two quadratic functions (drawn in red and blue) are trapped between two pure growth functions (drawn in black), and the minimum possible value of n 0 in each case is indicated.在该图中,两个二次函数(以红色和蓝色绘制)被困在两个纯增长函数(以黑色绘制)之间,并指示了每种情况下n 0的最小可能值。

在此处输入图像描述

So once you've picked your values of c 1 and c 2 , you can find the value of n 0 by intersecting your function with the two pure growth functions and taking the rightmost intersection.因此,一旦您选择了c 1c 2的值,您就可以通过将 ZC1C425268E68385D145074C17A4 与两个纯增长函数相交来找到n 0的值。

But you don't care about the getting smallest possible value for n 0 — we're doing asymptotics here, so any big enough value will do — so you can use approximations to get an upper bound on it.但是你并不关心获得n 0最小可能值——我们在这里做渐近,所以任何足够大的值都可以——所以你可以使用近似值来获得它的上限。

See davin's answer for how to get the upper bound for n 0 into the form given in CLRS.请参阅 davin 的回答,了解如何将n 0的上限转换为 CLRS 中给出的形式。

To prove that any polynomial f(n)=a0+a1*n+a2*n^2+a3*n^3+...+am*n^m is theta(n^m), follow two simple steps.要证明任何多项式 f(n)=a0+a1*n+a2*n^2+a3*n^3+...+am*n^m 是 theta(n^m),请遵循两个简单的步骤。 step 1. show that f(n) is bigOh(n^m) step 2. show that f(n) is bigOmega(n^m)步骤 1. 证明 f(n) 是 bigOh(n^m) 步骤 2. 证明 f(n) 是 bigOmega(n^m)

If both the above conditions hold good, then definitely f(n) is bigTheta(n^m).如果上述两个条件都成立,那么 f(n) 肯定是 bigTheta(n^m)。

This is a generalization.这是一个概括。 By putting m=2, you get f(n) is bigTheta(n^2) Simple.. isn't it?通过设置 m=2,你得到 f(n) is bigTheta(n^2) 简单..不是吗?

well its easy 1.c1<=a + b/n + c/n^2 Now here a is >0 while b,c are either positive or negative Now we must choose value of n such that b/n + c/n^2 never exceeds a in RHS of above eqution cause else it will become negative and so will c1.那么它很容易 1.c1<=a + b/n + c/n^2 现在这里 a >0 而 b,c 是正数或负数 现在我们必须选择 n 的值,使得 b/n + c/n ^2 永远不会超过上述方程的 RHS 中的 a,否则它将变为负数,c1 也是如此。 but by definition c1 is a positive constant但根据定义 c1 是一个正常数

So we want to make sure a>b/n+c/n^2所以我们要确保 a>b/n+c/n^2

if we choose n=2*max(|b|/a, sqrt(|c|/a) ) we will get b/n + c/n^2 as an expression whose value is less than a/2+a/4.如果我们选择 n=2*max(|b|/a, sqrt(|c|/a) ) 我们将得到 b/n + c/n^2 作为表达式,其值小于 a/2+a/ 4.

thus a+b/n+c/n^2 will have maximum value as a+a/2+a/4 and minimum value as a-(a/2+a/4) which is nothing but values of c2 and c1.因此 a+b/n+c/n^2 将具有最大值为 a+a/2+a/4 和最小值为 a-(a/2+a/4) 这只是 c2 和 c1 的值.

c1=aa/2-a/4= a/4 c2=a+a/2+a/4= 7a/4 c1=aa/2-a/4= a/4 c2=a+a/2+a/4= 7a/4

This concept can be extended to any values for any polynomial..这个概念可以扩展到任何多项式的任何值。

cheers!!!干杯!!!

P(n) = an 2 + bn + c = an 2 ( 1 + b / ( an ) + c / ( an 2 )) = an 2 ( 1 ± ( | b | / a ) / n ± ( √( | c | / a ) / n ) 2 P(n) = an 2 + bn + c = an 2 ( 1 + b / ( an ) + c / ( an 2 )) = an 2 ( 1 ± ( | b | / a ) / n ± ( √ ( | c | / a) / n) 2
so if we take for example q = max( | b | / a, √( | c | / a )) than因此,如果我们以q = max( | b | / a, √( | c | / a )) 为例
P(n) ≤ an 2 ( 1 + ( q / n ) + ( q / n ) 2 ) and if we take n 0 = q than we'll get the second constant P(n) ≤ an 2 ( 1 + ( q / n ) + ( q / n ) 2 )如果我们取n 0 = q ,我们将得到第二个常数
c 2 = 3a analogically for the lower bound c 2 = 3a类似地用于下限

c1 and c2 can be chosen arbitrarily, as long as 0 < c1 < a and a < c2 < infinity . c1c2可以任意选择,只要0 < c1 < aa < c2 < infinity即可。 n0 is then calculated from this, so that the inequality 0 <= c1*n^2 <= an^2 + bn + c <= c2*n^2 is satisfied for all n>=n0 .然后根据此计算n0 ,以便所有n>=n0满足不等式0 <= c1*n^2 <= an^2 + bn + c <= c2*n^2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM