Asymptotic Notation

Asymptotic Notation

To accurately predict the growth in run time for large instances, we
  1. take a program's code and determine step count to get T(n)
  2. get T(n) in "closed-form" (i.e., no summations - just in terms of n)
  3. [if needed] prove that our closed-form expression is correct (using induction)

Once we have a valid T(n) we want to compare the run time of one program with another.
Consider two simple programs whose only variation in T(n) is a coefficient (a loop that had an additional line or two):
Consider: T(n) = 2n2 +3n     and     T(n) = n2 +3n

Look at their graphs.
Note that coefficients do not make T(n) grow near as fast as various functions of n.

Consider some functions and their common names
Now get some values of these functions for various n. (Notice chosen values of n - since log2 are integers for powers of 2)
Finally, graph them as n gets large.

Now go back and consider how some I gave to you compare. Make a chart of values to see the rate of growth to determine which is < the other as n gets big. (To cheat, see page 111 in text.)
What we are doing is seeing when functions are asymptotically bigger(or smaller) than one another. I.E. which one grows faster than the other.

Formal Definitions

(Section 3.3 of text)

Note that this is saying that f(n) is asymptotically smaller than or equal to g(n)

e.g. Suppose T(n) = (n + 1) 2
then
   T(n) is O(n2)

Verify:

To show this to me so I know you know what you are talking about your math has to be very clear.
(n +1)2      < 4n2
n2 + 2n +1 < 4n2
0              < 4n2 - (n2 + 2n + 1)
0              < 3n2 - 2n - 1 for n > 1        OK

(why not n3 ) (lub)

T(n) is O(n2 ) for some program means there are positive constants c and no such that for n > no we have T(n) < cn2

verify T(n) = 3n3 + 2n2 is O(n3) (what does that mean?)


Discuss

* Prove Theorem 3.1 (page 119) ... makes polynomials easy

(can always get a big enough c, no )

Theorem: If f(n)=amnm + ... + a1n + a0 , then f(n) = O(nm).

Proof:
hints for proof:

  1. nm * ni-m = nm+i-m = ni
    then
  2. notice if ni-m have negative exponents => fractions
    n * fraction < n* 1.
  3. Finally let c = the summation of | ai | and no = 1
    e.g.,
    6n3 + 5n2 +4n + 2 < 6n3 + 5n3 + 4n3 +2n3 = 17n3
OK, here is the proof:

So, f(n) = O(nm) (assuming that m is fixed)

DONE

WHY?
Remember:
f(n) = O(g(n)) iff there exists positive constants c and no such that f(n) < cg(n) for all n , n > no
Our g(n) is nm, let be   c

So, given:

Often, we use no = 1 since it makes things easy to see.

One can always "play" for a proper no and c. You only need one to work to show the definition holds, so pick one that is easy to allow you to verify.

f(n) = O(g(n)) says g(n) is an upper bound ... does not say how good. To be informative, want smallest (least upper bound)

another example:

(what is no and what is c?)

What about

Omega

page 119

iff there exists positive constants c and no such that f(n) > cg(n) for all n , n > no (g is lower bound)

Example 3.15 page 120 (and here)

verify
(what does that mean?)

Theta

iff there exists positive constants c1, c2 and no such that c1g(n) < f(n) < c2g(n) for all n , n > no

verify
(what does that mean?)

Example 3.18 page 121 (and here)

if upper = lower --> algorithm is "best possible"

only way to make faster is faster hardware

HOWEVER, algorithmic improvement is more useful than hardware improvement Big chart of times
another chart of times and
and suppose computer improvements

Problems: Page 115: numbers 2, 3, 5 (but use the formal definition rather than the "working definition", Page 124: Numbers 9 and 11 (Don't forget that some answers are on the book website)

If you still want more info, see MIT slides (for this class only to slide 18)