Presentation is loading. Please wait.

Presentation is loading. Please wait.

nalisis de lgoritmos A A

Similar presentations


Presentation on theme: "nalisis de lgoritmos A A"— Presentation transcript:

1 nalisis de lgoritmos A A
Informacion tomada del Depto. De sistemas de la Universidad Nacional sede Bogota.

2 OUTLINE Growth of Functions Asymptotic notation Common functions

3 ASYMPTOTIC NOTATION

4 Asymptotically No Negative Functions
f(n) is asymptotically no negative if there exist n0  N such that for every n  n0, 0  f(n) f n0

5 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) g c2g f c1g n0

6 “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)) = .

7 Example Lets show that We have to find c1,c2 and n0 such that

8 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.

9 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.

10 Thus by choosing c1 = 1/14, c2 = 1/2 and n0 =7 then we can verify that

11 O(g(n)) = {f: N R* | ( cR +) (n0N) (n n0) ( 0  f(n)  cg(n) )}
Big O O(g(n)) = {f: N R* | ( cR +) (n0N) (n n0) ( 0  f(n)  cg(n) )} lim f(n)  c n  g(n) cg g f n0

12 “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)”

13 We have to find c and n0 such that
Example Lets show that We have to find c and n0 such that

14 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

15 a+b a b n0=1

16 Big Omega   (g(n)) ={ f: N R* | ( cR +) (n0N) ( n n0) ( 0 cg(n)  f(n) ) } c  lim f(n) n  g(n) g cg f n0

17 “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)”

18 “o(g(n)) functions that grow slower than g ”
Little o o (g(n)) = { f : N R* | (c R +) (n0N) ( n n0) ( 0  f(n) < cg (n) ) } lim f(n) = 0 n  g(n) “o(g(n)) functions that grow slower than g ” g f

19 “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)”

20 Examples Lets show that We only have to show n2 n

21 Lets show that We have 3n n

22 “ (g(n)) functions that grow faster than g ”
Little Omega   (g(n)) = { f : N R* | (cR +) (n0N) ( n n0) ( 0  c g(n) < f(n) ) } lim f(n) =  n  g(n) “ (g(n)) functions that grow faster than g ” f g

23 “f(n) =  (g(n))”  “f(n)   (g(n))”
f is asymptotically larger than g o(g(n)) is pronounced “little-omega of g(n)”

24 Analogy with the comparison of two real numbers
Asymptotic Real Notation numbers f(n) O(g(n)) f  g f(n) (g(n)) f  g f(n) (g(n)) f = g f(n) o(g(n)) f < g f(n) (g(n)) f > g Trichotomy does not hold

25 Example f(n)=n g(n)=n(1+sin n) (1+sin(n))  [0,2] Not all functions are asymptotically comparable

26 The running time of an algorithm is (f(n)) iff
Properties  (f(n))=O(f(n))  (f(n)) The running time of an algorithm is (f(n)) iff Its worst-case running time is O(f(n)) and Its best-case running time is  (f(n))

27 f(n)  (g(n)) and g(n)  (h(n)) then f(n)  (h(n)) ;
Transitivity of O,  ,  f(n)  (g(n)) and g(n)  (h(n)) then f(n)  (h(n)) ; for  = O,  ,  Reflexivity of O,  ,  f(n)  (f(n)) ; for  = O,  ,  Symmetry of  f(n)  (g(n))  g(n)  (f(n)) Anti-symmetry of O,  f(n)   (g(n)) f(n)  (g(n))  g(n)  (f(n)) ; for  = O,  Transpose Symmetry f(n) O(g(n))  g(n)  (f(n)) f(n) o(g(n))  g(n)  (f(n))

28 f  g  f(n) O(g(n)) order relation
reflexive anti-symmetric transitive f  g  f(n)  (g(n)) order relation f = g  f(n)  (g(n)) equivalence relation symmetric

29 Relation between o and O
f(n) o(g(n))  f(n) O(g(n)) Relation between  and  g(n)  (f(n)) g(n)  (f(n)) o(f(n))   (f(n)) = 

30 Examples A B 5n n 3n2 + 2 log3(n2) log2(n3) nlg4 3lg n lg2n n1/2

31 Examples A B 5n2 + 100n 3n2 + 2 A  (B) log3(n2) log2(n3) A  (B)
nlg4 3lg n A  w(B) lg2n n1/2 A  o (B)

32 Examples A B 5n2 + 100n 3n2 + 2 A  (B) log3(n2) log2(n3) 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  w(B) alog b = blog a; B =3lg n=nlg 3; A/B =nlg(4/3)   as n lg2n n1/2 A  o (B) lim ( loga n / nb ) = 0, here a = 2 and b = 1/2  A  o (B) n

33 Asymptotic notation two 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)) }

34 COMMON FUNCTIONS

35 Monotonicity f is monotonically increasing if m n  f(m) f(n)
f is monotonically decreasing if m n  f(m) f(n) f is strictly increasing if m < n  f(m) < f(n) f is strictly decreasing if m < n  f(m) > f(n)

36 Floors and Ceilings x floor of x x ceiling of x
the greatest integer less than or equal to x x ceiling of x the smallest integer greater than or equal to x x  R , x-1 < x  x  x < x +1 n  N , n = n = n and n/2 + n/2 = n -1 1 x -2 2 x x

37 x and x are monotonically increasing
x  R 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

38 Modular 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.

39 congruency or equivalence mod 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 that a is congruent to b modulo n. In other words a  b (mod n) if a and b have the same remainder when divided by n. Also a  b (mod n) if and only if n is a divisor of b-a.

40 relation in Z and produces a partitioned set called
Example  (mod 4)  (mod n) defines a equivalence relation in Z and produces a partitioned set called Zn= Z/n ={0,1,2,…,n-1} in which can be defined arithmetic operations a+b (mod n) a*b (mod n) -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 1 2 3 4 5 6 7 8 9 10 11 Z/4={[0],[1],[2],[3]}={0,1,2,3} 4+1 (mod 4) = 1 5*2 (mod 4) = 2 12 13 14 15 [0] [1] [2] [3]

41 Polynomials Given a no negative integer d, a polynomial in n of
degree d is a function p(n) of the form: Where a1 ,a2 ,…, ad are the coefficients and ad  0.

42 f(n)=O(nd) for some constant d.
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  R , a  0, na is monotonically increasing. a  R , a  0, na is monotonically decreasing. A function f(n) is polynomially bounded if f(n)=O(nd) for some constant d.

43 Exponentials 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

44 If a  0 and for all n, an is monotonically increasing. a,b  R , a >1, then nd = o(an)

45 x  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) .

46 Logarithms 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 the formula lg n + k = (lg n ) +k. For b > 1 constant and n > 0, logb n is strictly increasing.

47 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.

48 when x > -1 For x > -1 equality holds for x=0.

49 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 )

50 Factorials Definition (no recursive) (recursive) Weak upper bound
n!  nn

51 Stirling´s approximation
then n! = o(nn) n! =  (2n) lg(n!) = (n lgn)

52 where

53 Functional 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,

54 Examples: f(n) = 2n then f(n) = n2 then

55 f(n) = nn then

56 Iterated 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* = 4 lg* (65536)2 = 5

57 In general k


Download ppt "nalisis de lgoritmos A A"

Similar presentations


Ads by Google