How do i prove this inequality

170 Views Asked by At

Im trying to prove that $f(n)=an^2 +bn+c$ where $a,b,c$ are constants is $\Theta(n^2)$ through inequalities.

$$0 \le c_1n^2 \le an^2 + bn + c \le c_2n^2 \text{ for all } n \ge n_0$$

The book gave an answer with no explenation.

$$c_1 = \frac{a}{4}$$

$$c_2 = \frac{7a}{4}$$

$$n_0 = 2 \max\bigg(\frac{|b|}{a}, \sqrt{\frac{|c|}{a}}\bigg)$$

I'm puzzled on how we got that.

Picture from book(intro to Algorithms, chapter 3 page 46) enter image description here

Edit: Proving that f(n)=n^2 +2n is theta(n^2)

c1*g(n)<=n^2 + 2n <=c2*g(n)

c1*n^2 <=n^2 + 2n <= c2*n^2

c1<= 2/n <=c2

We can make the right hand side 2/n <=c2 hold for n=>1 if we pick c2=2

We can make the left hand side c1<=2/n hold for n=>1 if we pick c1=2

Therefore with constants c1 and c2 eqaualing 2 and n => 1 we can verify that for some n_0 => 1 f(n) is theta(n^2)

I based my proof off of another example in the book that was similar:

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Now, to give you a rough idea of what was done here:

To get that $f=\Theta(n^2)$, we need to talk about absolute values. After all, $f(n)=-n^2=\Theta(n^2)$ as well.

If $a,b,c$ were all positive, the question would be fairly easy - we could choose $c_1=a,\quad c_2=a+b+c$ and we are done.

So, we need to figure out what happens if we get some negatives in there.

Basically, the first thing you choose is a constant $c_1$ with absolute value smaller than $a$. If you do this, then asymptotically, your statement $|c_1n^2|\leq |an^2+bn+c|\approx |an^2|$ will hold - of course, that's merely the idea behind it, since using this as a proof would be kind of going around in a circle.

So, in this case we have chosen $c_1=\frac{a}{4}$, which certainly fulfills that condition. It is not the most intuitive choice, at least for me, but works anyway - after all, any constant as above can be made to work, just with probably a bit more calculations.

Now, we have to prove our first inequality, we want to find a $n_0$, such that for $n>n_0$ this inequality certainly holds.

We have $|an^2+bn+c|\geq |a|n^2-|b|n-|c|$ by the triangle inequality.

Thus, if we have $|a|n^2-|b|n-|c|\geq |\frac{a}{4}|n^2$, then we are done.

Now, this inequality simplifies to $|\frac{3a}{4}|n^2-|b|n-|c|\geq 0$.

Calculating the zeros (there might be a much prettier way, but this is probably the most standard approach), we have the inequality holding for $n_0\geq \frac{-|b|+\sqrt{b^2+3|a||c|}}{\frac{3}{2}|a|}=:T(a,b,c)$, and you immediately get $T(a,b,c)\leq 2\frac{\sqrt{b^2+3|a||b|}}{3|a|}$ - I'd suggest you check the calculations, though, to make sure I didn't mess up somewhere. If you now look at whether $b^2\geq 3|a||c|$ or not, you can - using some fairly gross estimates - show that in either case one of your given values for $n_0$ will hold true.

For $c_2$ we do the very same thing, though I don't actually want to write all of that down, I'll just trust your book to be correct this instance.