clase3 notacion

57
nalisis de nalisis de lgoritmos lgoritmos Informacion tomada del libro de Cormen.

Upload: luzenithg

Post on 14-Jun-2015

1.297 views

Category:

Education


4 download

DESCRIPTION

Descripción de las Notaciones asintoticas

TRANSCRIPT

Page 1: Clase3 Notacion

nalisis denalisis de

lgoritmoslgoritmos

Informacion tomada del libro de Cormen.

Page 2: Clase3 Notacion

OUTLINEOUTLINE

Growth of FunctionsGrowth of Functions

• Asymptotic notationAsymptotic notation

• Common functionsCommon functions

Page 3: Clase3 Notacion

ASYMPTOTIC NOTATIONASYMPTOTIC NOTATION

Page 4: Clase3 Notacion

Asymptotically No Negative Functions

f(n) is asymptotically no negative if there exist n0 N such that for every n n0,

0 f(n)

nn00

ff

Page 5: Clase3 Notacion

Theta Theta (g(n)) ={ f : N R* | ( c1, c2 R +) ( n0 N) ( n n0) (0 c1 g(n) f(n) c2 g(n)) }

c1 lim f(n) c2

n g(n)

n0

g

c1gf

c2g

Page 6: Clase3 Notacion

“f(n) = (g(n))” “f(n) (g(n))”

f is asymptotically tight bound for g

or

f is of the exact order of g

Every member of (g(n)) is asymptotically no negative

The function g(n) must itself asymptotically no negative, or else (g(n)) = .

Page 7: Clase3 Notacion

Example

Lets show that

We have to find c1,c2 and n0 such that

22

221 3

21

ncnnnc

22 321

nΘnn

Page 8: Clase3 Notacion

For all n n0, Dividing by n2 yields

We have that 3/n is a decreasing sequence

3, 3/2, 1, 3/4, 3/5, 3/6, 3/7…

and then 1/2 - 3/n is increasing sequence

-5/2, -1, -1/2, -1/4, -1/10, 0, 1/14

that is upper bounded by 1/2.

21

321

cn

c

Page 9: Clase3 Notacion

1/2 - 3/n

-3

-2.5

-2

-1.5

-1

-0.5

0

0.5

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1/2 - 3/n

The right hand inequality can be made to hold for n 1 by choosing c2 1/2. Likewise the left hand inequality can be made to hold for n 7 by choosing c1 1/14.

Page 10: Clase3 Notacion

-20

0

20

40

60

80

100

120

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1/14 n 2̂

1/2n^2 - 3n

1/2 n^2

Thus by choosing c1 = 1/14, c2 = 1/2 and n0

=7 then we can verify that

22 321

nΘnn

Page 11: Clase3 Notacion

Big Big OO

O(g(n)) = {f: N R* | ( cR +) (n0N) (n n0) ( 0 f(n) cg(n) )}lim f(n) cn g(n)

n0

g cg

ff

Page 12: Clase3 Notacion

“f(n) = O (g(n))” “f(n) O (g(n))”

f is asymptotically upper bounded for g

or

g is an asymptotic upper bound for f

O (g(n)) is pronounced “big oh of g(n)”

Page 13: Clase3 Notacion

Example

Lets show that

We have to find c and n0 such that

nOban

cnban

Page 14: Clase3 Notacion

For all n n0, Dividing by n yields

The inequality can be made to hold for n 1 by choosing c a+b. Thus by choosing c = a+b and n0 =1 then we can verify that

cnb

a

nOban

Page 15: Clase3 Notacion

n0=1

a+b

ba

Page 16: Clase3 Notacion

Big Omega Big Omega (g(n)) ={ f: N R* | ( cR +) (n0N) ( n n0) ( 0 cg(n) f(n) ) }

c lim f(n) n g(n)

n0

g

f cg

Page 17: Clase3 Notacion

“f(n) = (g(n))” “f(n) (g(n))”

f is asymptotically lower bounded for g

or

g is an asymptotic lower bound for f

O (g(n)) is pronounced “big omega of g(n)”

Page 18: Clase3 Notacion

Little Little ooo (g(n)) = { f : N R* | (c R +) (n0N) ( n n0) ( 0 f(n) < cg (n) ) }

lim f(n) = 0n g(n)

“o(g(n)) functions that grow slower than g ”

g

f

Page 19: Clase3 Notacion

“f(n) = o(g(n))” “f(n) o (g(n))”

f is asymptotically smaller than g

o(g(n)) is pronounced “little-oh of g(n)”

Page 20: Clase3 Notacion

Examples

Lets show that

We only have to show

2non

01

2 n

limnn

limnn

nn2

n

Page 21: Clase3 Notacion

Lets show that

We have

non 3

031

31

3

nnlim

nn

lim

3n3nn

Page 22: Clase3 Notacion

Little Omega Little Omega (g(n)) = { f : N R* | (cR +) (n0N) ( n n0) ( 0 c g(n) < f(n) ) }

lim f(n) = n g(n)

“ (g(n)) functions that grow faster than g ”

ff

g

Page 23: Clase3 Notacion

“f(n) = (g(n))” “f(n) (g(n))”

f is asymptotically larger than g

o(g(n)) is pronounced “little-omega of g(n)”

Page 24: Clase3 Notacion

Analogy with the comparison of two real numbers

AsymptoticAsymptotic RealReal NotationNotation numbersnumbers

f(n) O(g(n)) f gf(n) (g(n)) f gf(n) (g(n)) f = gf(n) o(g(n)) f < gf(n) (g(n)) f > g

Trichotomy does not hold

Page 25: Clase3 Notacion

Example

f(n)=ng(n)=n(1+sin n)

(1+sin(n)) [0,2]

0

100

200

300

400

500

600

700

1 3 5 7 9 11 13 15 17 19 21 23 25

n

n

n (̂1+sin n)

n 2̂

Not all functions are asymptotically comparable

Page 26: Clase3 Notacion

The running time of an algorithm is The running time of an algorithm is (f(n))

iffiff

• Its worst-case running time is Its worst-case running time is O(f(n)) andand

• Its best-case running time is Its best-case running time is (f(n))

(f(n))=O(f(n)) (f(n))

PropertiesProperties

Page 27: Clase3 Notacion

• Transitivity ofTransitivity of O, , f(n) (g(n)) and g(n) (h(n)) then f(n) (h(n)) ;;

for = O, , • Reflexivity ofReflexivity of O, ,

f(n) (f(n)) ; ; for = O, , • Symmetry of Symmetry of

f(n) (g(n)) g(n) (f(n)) • Anti-symmetry of Anti-symmetry of O,

f(n) (g(n)) f(n) (g(n)) g(n) (f(n)) ;; for = O,

• Transpose SymmetryTranspose Symmetryf(n) O(g(n)) g(n) (f(n))f(n) o(g(n)) g(n) (f(n))

Page 28: Clase3 Notacion

• f g f(n) O(g(n)) order relationorder relation reflexive anti-symmetric transitive

• f g f(n) (g(n)) order relationorder relation reflexive anti-symmetric transitive

• f = g f(n) (g(n)) equivalence relationequivalence relation reflexive symmetric transitive

Page 29: Clase3 Notacion

• Relation between Relation between o and and O

f(n) o(g(n)) f(n) O(g(n))

• Relation between Relation between and and

g(n) (f(n)) g(n) (f(n))

o(f(n)) (f(n)) =

Page 30: Clase3 Notacion

ExamplesExamples

AA BB

5n5n22 + 100n + 100n 3n3n22 + 2 + 2

loglog33(n(n22)) loglog22(n(n33))

nnlg4lg4 33lg nlg n

lglg22nn nn1/21/2

Page 31: Clase3 Notacion

ExamplesExamples

AA BB

5n5n22 + 100n + 100n 3n3n22 + 2 + 2 A A (B)(B)

loglog33(n(n22)) loglog22(n(n33)) A A (B)(B)

nnlg4lg4 33lg nlg n A A (B)(B)

lglg22nn nn1/21/2 A A (B)(B)

Page 32: Clase3 Notacion

ExamplesExamples

A B

5n2 + 100n 3n2 + 2 A (B)A (n2), n2 (B) A (B)

log3(n2) log2(n3) A (B)logba = logca / logcb; A = 2lgn / lg3, B = 3lgn, A/B =2/(3lg3)

nlg4 3lg n A (B)alog b = blog a; B =3lg n=nlg 3; A/B =nlg(4/3) as n

lg2n n1/2 A (B)lim ( loga n / nb ) = 0, here a = 2 and b = 1/2 A (B) n

Page 33: Clase3 Notacion

Asymptotic notation Asymptotic notation two variablestwo variables

O(g(m, n))={ f: N N R* | ( c R +)( m0 , n0 N) ( n n0) ( m m0)

(f(m, n) c g(m, n)) } }

Page 34: Clase3 Notacion

COMMON FUNCTIONSCOMMON FUNCTIONS

Page 35: Clase3 Notacion

MonotonicityMonotonicity

• f is monotonically increasing ifis monotonically increasing if m n f(m) f(n)

• f is monotonically decreasing ifis monotonically decreasing if m n f(m) f(n)

• f is strictly increasing ifis strictly increasing if m < n f(m) < f(n)

• f is strictly decreasing ifis strictly decreasing if m < n f(m) > f(n)

Page 36: Clase3 Notacion

Floors and CeilingsFloors and Ceilings

x floor of floor of xx the greatest integer less than or equal to x

x ceiling of ceiling of xx the smallest integer greater than or equal to x

x RR , x-1 < x x x < x +1

n NN , n = n = n and n/2 + n/2 = n

-1 0 1 x-2 2 xx

Page 37: Clase3 Notacion

x RR and integers a,b > 0

x/a /b = x /ab .

x/a /b = x /ab .

a /b ( a + (b-1)) /b.

a /b ( a - (b-1)) /b.

x and x are monotonically increasing

Page 38: Clase3 Notacion

Modular arithmeticModular arithmetic

For every integer a and any possible positive integer n,

a mod n

is the remainder of ( or residue) of the quotient a/n

a mod n = a - a /n n.

Page 39: Clase3 Notacion

congruency or equivalence modcongruency or equivalence mod n n

If (a mod n) = (b mod n) we write

a b (mod n)

and we say that a is equivalent to b modulo n or thata is congruent to b modulo n.

In other words a b (mod n) if a and b have the sameremainder when divided by n.Also a b (mod n) if and only if n is a divisor of b-a.

Page 40: Clase3 Notacion

0 1 2 3

-4 -3 -2 -1

-8 -7 -6 -5

-12 -11 -10 -9

12 13 14 15

8 9 10 11

4 5 6 7

Example (mod 4) (mod n)

defines a equivalence relation in Z Z and produces a

partitioned set called ZZn= ZZ/n ={0,1,2,…,n-1}in which can be defined

arithmetic operationsa+b (mod n) a*b (mod n)

[0] [1] [2] [3]

ZZ/4={[0],[1],[2],[3]}={0,1,2,3}

4+1 (mod 4) = 15*2 (mod 4) = 2

Page 41: Clase3 Notacion

PolynomialsPolynomials

Given a no negative integer d, a polynomial in n ofdegree d is a function p(n) of the form:

Where a1 ,a2 ,…, ad are the coefficients and ad 0.

.)(0

id

iinanp

Page 42: Clase3 Notacion

• A polynomial p(n) is asymptotically positive if and only if ad > 0.

• If p(n), of degree d, is asymptotically positive, we have p(n)= (nd).

a RR , a 0, na is monotonically increasing.

a RR , a 0, na is monotonically decreasing.

• A function f(n) is polynomially bounded if

f(n)=O(nd) for some constant d.

Page 43: Clase3 Notacion

ExponentialsExponentials

• For all reals a 0, m and n, we have the following identities

• a0 = 1• a1 = a• a -1 = 1/a• (am)n = amn

• (am)n = (an)m

• am an=am+n

Page 44: Clase3 Notacion

• If a 0 and for all n,

an is monotonically increasing.

a,b RR , a >1,

then nd =

o(an)

0 n

d

n an

lim

Page 45: Clase3 Notacion

x R,R, ex 1+x, equality holds for x=0.

• If |x| 1 1+x ex 1+x+ x2 .

• When x 0, ex = 1+x +O(x2) .

0

5432

!!5!4!3!21

i

ix

ixxxxx

xe

n

n

x

nx

lime

1

Page 46: Clase3 Notacion

LogarithmsLogarithms

Notations:• lg n = log2 n• ln n = loge n• lgk n = (lg n ) k

• lg lg n = lg (lg n )

Logarithms function will only apply to next term in theformula

lg n + k = (lg n ) +k.

For b > 1 constant and n > 0, logb n

is strictly increasing.

Page 47: Clase3 Notacion

• For all reals a > 0, b > 0, c > 0 and n we have the following identities

• • logc (ab) = logc a + logc b.

• logb an = n logb a.

• logb (1/an) = - logb a.

.log abba

.loglog

logba

ac

cb

.log

1log

ba

ab

.loglog ac bb ca

Page 48: Clase3 Notacion

when x > -1

• For x > -1

equality holds for x=0.

1

15432 )1(5432

)1ln(i

ii

ixxxxx

xx

xxx

x

)1ln(1

Page 49: Clase3 Notacion

A function f(n) is polylogaritmically bounded if

f(n)=O(lgk n) for some constant k.

We have the following relation between polynomials and polylogarithms:

then lgk n = o(nk )

ndndnd d

nlglglg 222

.02

lglglg

nd

k

nd

k

n

nlim

nn

lim

Page 50: Clase3 Notacion

FactorialsFactorials

Definition

(no recursive)

(recursive)

Weak upper bound n! nn

0

01!

1

nifi

nifn n

i

0)!1(

01!

nifnn

nifn

Page 51: Clase3 Notacion

Stirling´s approximation

thenn! = o(nn)

n! = (2n)

lg(n!) = (n lgn)

nen

nnn

11π2!

Page 52: Clase3 Notacion

where

nn n 121

1121

neen

nnn

π2!

Page 53: Clase3 Notacion

Functional iterationFunctional iteration

Given a function f (n) the i-th functional iteration of f is defined as :

with I the identity function. For a particular n, we have,

0

01 iifff

iifIf i

i

0

01 iifnff

iifnnf i

i

Page 54: Clase3 Notacion

Examples:

f(n) = 2n then

f(n) = n2 then

nnf ii 2

i

nnf

nnnnf

nnnnf

nnnnnnf

i 2

162*2*2*222*2*24

82*2*222*23

42*222222

Page 55: Clase3 Notacion

f(n) = nn then

n

nn

nnn

nn

n

ni

n

n

n

nnf

nnf

nnf

nnf

4

3

2

Page 56: Clase3 Notacion

Iterated logarithmIterated logarithm

The iterated logarithm of n, denoted lg* n “log star of n”is defined as

lg* n , is a very slowly growing function

lg* 1 = 0 lg* 2 = 1 lg* 4 = 2 lg* 16 = 3

lg* 65536 = 4 lg* (65536)2 = 5

1lg|0lg* niminn i

Page 57: Clase3 Notacion

In general

k2

2222* 2lgk