Processing math: 100%
Close
Close Window

Show Source |    | About   «  21.5. Bounds Review   ::   Contents   ::   21.7. Summation Techniques  »

21.6. Growth Rates Review

21.6.1. Growth Rates Review

Two functions of n have different growth rates if as n goes to infinity their ratio either goes to infinity or goes to zero.

The growth rates for five equations

Figure 21.6.1: Two views of a graph illustrating the growth rates for six equations. The bottom view shows in detail the lower-left portion of the top view. The horizontal axis represents input size. The vertical axis can represent time, space, or any other measure of cost.

Where does (1.618)n go on here?

Exact equations relating program operations to running time require machine-dependent constants. Sometimes, the equation for exact running time is complicated to compute. Usually, we are satisfied with knowing an approximate growth rate.

Example: Given two algorithms with growth rate c1n and c22n!, do we need to know the values of c1 and c2?

Consider n2 and 3n. PROVE that n2 must eventually become (and remain) bigger.

Proof by Contradiction: Assume there are some values for constants r and s such that, for all values of n, n2<rn+s. Then, n<r+s/n. But, as n grows, what happens to s/n? It goes to zero.

Since n grows toward infinity, the assumption must be false. Conclusion: In the limit, as n, constants don’t matter. Limits are the typical way to prove that one function grows faster than another.

Here are some useful observatios.

Since n2 grows faster than n,

  • 2n2 grows faster than 2n. (Take antilog of both sides.)

  • n4 grows faster than n2. (Square boths sides.)

  • n grows faster than n. (n=(n)2. Replace n with n.)

  • 2logn grows no slower than logn. (Take log of both sides. Log “flattens” growth rates.)

Since n! grows faster than 2n,

  • n!! grows faster than 2n!. (Apply factorial to both sides.)

  • 2n! grows faster than 22n. (Take antilog of both sides.)

  • n!2 grows faster than 22n. (Square both sides.)

  • n! grows faster than 2n. (Take square root of both sides.)

  • logn! grows no slower than n. (Take log of both sides. Actually, it grows faster since logn!=Θ(nlogn).)

If f grows faster than g, then must f grow faster than g? Yes.

Must logf grow faster than logg? No. lognlogn2 within a constant factor, that is, the growth rate is the same!

logn is related to n in exactly the same way that n is related to 2n.

2logn=n.

21.6.1.1. Asymptotic Notation

little ohf(n)o(g(n))<limf(n)/g(n)=0big ohf(n)O(g(n))Thetaf(n)=Θ(g(n))=f=O(g)andg=O(f)Big Omegaf(n)Ω(g(n))LittleOmegaf(n)ω(g(n))>limg(n)/f(n)=0

I prefer “fO(n2)” to “f=O(n2)” While nO(n2) and n2O(n2), O(n)O(n2).

Note: Big oh does not say how good an algorithm is—only how bad it can be.

If AO(n) and BO(n2), is A better than B? Perhaps… but perhaps better analysis will show that A=Θ(n) while B=Θ(logn).

Order Notation has practical limits. Notation: logn2(=2logn) vs. log2n(=(logn)2) vs. loglogn.

log162=2log16=8.

log216=42=16.

loglog16=log4=2.

Statement: Resource requirements for Algorithm A grow slower than resource requirements for Algorithm B.

Is A better than B?

Potential problems:

  • How big must the input be?

  • Some growth rate differences are trivial Example: Θ(log2n) vs. Θ(n1/10). If n is 1012(240) then log2n1600, n1/10=16 even though n1/10 grows faster than log2n. n must be enormous (like 2150) for n1/10 to be bigger than log2n.

It is not always practical to reduce an algorithm’s growth rate “Practical” here means that the constants might become too much higher when we shave off the minor asymptotic growth.

Shaving a factor of n reduces cost by a factor of a million for input size of a million. Shaving a factor of loglogn saves only a factor of 4-5.

There is the concept of a “Practicality Window”. In general, (1) we have limited time to solve a problem, and (2) input can only get so big before the computer chokes. Fortunately, algorithm growth rates are USUALLY well behaved, so that Order Notation gives practical indications. “Practical” is the keyword. We use asymptotics because they provide a simple model that usually mirrors reality. This is useful to simplify our thinking.

   «  21.5. Bounds Review   ::   Contents   ::   21.7. Summation Techniques  »

Close Window