Sunteți pe pagina 1din 4

Chapter 2

Asymptotic Notation
You may be asking that we continue to use the notation but have never dened it. Lets remedy this
now. Given any Iunction gn, we dene gn to be a set oI Iunctions that asvmptoticallv equivalent
to gn. Formally:
gn n there exist positive
constants c

, c

and n

such that
0 c

gn n c

gn
Ior all n n

This is written as 'n gn That is, n and gn are asvmptoticallv equivalent. This means
that they have essentially the same growth rates Ior large n. For example, Iunctions like
4n

,
8n

2n 3,
n

,5

n 10 log n
nn 3
are all asymptotically equivalent. As n becomes large, the aominant (Iastest growing) term is some
constant times n

.
Consider the Iunction
n 8n

2n 3
Our inIormal rule oI keeping the largest term and ignoring the constant suggests that n n

. Let`s
see why this bears out Iormally. We need to show two things Ior
n 8n

2n 3
Lower bound n 8n

2n 3 grows asymptotically at least as Iast as n

,
23
24
Upper bound n grows no Iaster asymptotically than n

,
Lower bound: n grows asymptotically at least as Iast as n

. For this, need to show that there exist


positive constants c

and n

, such that n c

Ior all n n

. Consider the reasoning


n 8n

2n 3 8n

3 n

3 n

Thus c

. We implicitly assumed that 2n 0 and n

3 0 These are not true Ior all n but iI


n

3, then both are true. So select n

3. We then have n c

Ior all n n

.
Upper bound: n grows asymptotically no Iaster than n

. For this, we need to show that there exist


positive constants c

and n

, such that n c

Ior all n n

. Consider the reasoning


n 8n

2n 3 8n

2n 8n

2n

10n

Thus c

10. We implicitly made the assumption that 2n 2n

. This is not true Ior all n but it is true


Ior all n 1 So select n

1. We thus have n c

Ior all n n

.
From lower bound we have n

3 From upper bound we have n

1. Combining the two, we let n

be the larger oI the two: n

3. In conclusion, iI we let c

, c

10 and n

3, we have
n

8n

2n 3 10n

Ior all n

3
We have thus established
0 c

gn n c

gn Ior all n n

Here are plots oI the three Iunctions. Notice the bounds.


0
2e+10
4e+10
6e+10
8e+10
1e+11
0 20000 40000 60000 80000 100000
n
Asymptotic Notation
8n^2+2n-3
7n^2
10n^2
Figure 2.1: Asymptotic Notation Example
We have established that n n

. Let`s show why n is not in some other asymptotic class. First,


let`s show that n n. Show that n n. II this were true, we would have had to satisIy
25
both the upper and lower bounds. The lower bound is satised because n 8n

2n 3 does grow
at least as Iast asymptotically as n. But the upper bound is Ialse. Upper bounds requires that there exist
positive constants c

and n

such that n c

n Ior all n n

.
InIormally we know that n 8n

2n 3 will eventually exceed c

n no matter how large we make


c

. To see this, suppose we assume that constants c

and n

did exist such that 8n

2n 3 c

n Ior
all n n

Since this is true for all sufciently large n then it must be true in the limit as n tends to
innity. If we divide both sides by n, we have
lim

8n 2
3
n
c

.
It is easy to see that in the limit, the leIt side tends to . So, no matter how large c

is, the statement is


violated. Thus n n.
Let`s show that n n

. The idea would be to show that the lower bound n c

Ior all
n n

is violated. (c

and n

are positive constants). InIormally we know this to be true because any


cubic Iunction will overtake a quadratic.
II we divide both sides by n

:
lim

8
n

2
n


3
n

The leIt side tends to 0. The only way to satisIy this is to set c

0. But by hypothesis, c

is positive.
This means that n n

.
The denition of -notation relies on proving both a lower and upper asymptotic bound. Sometimes we
only interested in proving one bound or the other. The O-notation is used to state only the asymptotic
upper bounds.
Ogn n there exist positive
constants c and n

such that
0 n cgn
Ior all n n

The -notation allows us to state only the asymptotic lower bounds.


gn n there exist positive
constants c and n

such that
0 cgn n
Ior all n n

26
The three notations:
gn 0 c

gn n c

gn
Ogn 0 n cgn
gn 0 cgn n
Ior all n n

These denitions suggest an alternative way of showing the asymptotic behavior. We can use limits Ior
dene the asymptotic behavior. Limit rule for -notation:
lim

n
gn
c,
Ior some constant c 0 (strictly positive but not innity) then n gn. Similarly, the limit rule
Ior O-notation is
lim

n
gn
c,
Ior some constant c 0 (nonnegative but not innite) then n Ogn and limit rule Ior
-notation:
lim

n
gn
0,
(either a strictly positive constant or innity) then n gn.
Here is a list oI common asymptotic running times:
1: Constant time; can`t beat it!
log n: Inserting into a balanced binary tree; time to nd an item in a sorted array oI length n
using binary search.
n: About the Iastest that an algorithm can run.
nlog n: Best sorting algorithms.
n

: Polynomial time. These running times are acceptable when the exponent oI n is
small or n is not to large, e.g., n 1000.
2

: Exponential time. Acceptable only iI n is small, e.g., n 50.


n n

: Acceptable only Ior really small n, e.g. n 20.

S-ar putea să vă placă și