Algorithms and Discrete Mathematics 20062007 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Algorithms and Discrete Mathematics 20062007

Description:

By O(g(n)) ( read 'Big-O of g of n ) we denote the set of functions dominated by ... That is, we can increase c or n0, or decease the one and increase ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 20
Provided by: dur9
Category:

less

Transcript and Presenter's Notes

Title: Algorithms and Discrete Mathematics 20062007


1
Algorithms and Discrete Mathematics 2006/2007
  • Lecture 7
  • Fundamentals of Discrete Mathematics
  • Asymptotic Notation II

Ioannis Ivrissimtzis
17-Nov-2006
2
Overview of the lecture
  • Review of the Big-O notation
  • Examples

3
The Big-O notation
  • By O(g(n)) ( read Big-O of g of n ) we denote
    the set of functions dominated by g(n).
  • We commonly write
    instead of to
    denote that f(n) is a member of O(g(n)).

4
The Big-O notation
  • Some orders that often occur in practice are

5
Overview of the lecture
  • Review of the Big-O notation
  • Examples

6
Examples
  • Example 7.1 Let
  • f(n)5n, g(n)n2
  • where n is a positive integer.
  • The table gives f(n) and g(n) for small values of
    n.

7
Examples
  • We notice that f(n) g(n) for n 1,2,3,4.
  • But,
  • f(n) g(n) for n 5.
  • To see this notice that
  • n 5 n2 5n
  • So, with c 1 and n0 5, we have that for all n
    n0 , f(n) cg(n).
  • Therefore, g dominates f and thus f O(n2).

8
Examples
  • Remark
  • Other values of c,n0 would also work. For example
  • c1, n010
  • c2, n05
  • c5, n01
  • That is, we can increase c or n0, or decease the
    one and increase
  • the other without destroying the proof. Thus, c
    and n0 are not unique.
  • However, they must be fixed for the proof to be
    valid.

9
Examples
  • Remark
  • We proved that 5n O(n2).
  • That means that as n increases, the value of f
    will be (up to a constant)
  • at most n2.
  • However, we can further improve the result.
  • Exercise 7.1 Prove that 5n O(n).
  • Hint Use the definition with c 5, n0 1.

10
Examples
  • Example 7.2 Let
  • f(n)4n2 17n 5 , g(n)n2
  • with n a positive integer.
  • We have
  • f(n) 4n2 17n 5 4n2 17n2 5n2 26n2
    26g(n)
  • Because the above equation holds for every
    positive integer n, if we
  • choose n01 and c26 we have
  • f(n) cg(n)
  • Giving, f O(g), that is, f O(n2).

11
Examples
  • In the same example we have,
  • g(n) n2 4n2 17n 5 f(n)
  • for all n 1. Using any c 1, we get
  • g O(f).
  • Thus, we proved that O(f) O(g).
  • Remark
  • The trick of replacing all the terms of the
    polynomial 4n2 17n 5 with
  • n2 is quite common in such proofs. In fact, it is
    quite common in proving
  • inequalities.

12
Examples
  • Example 7.3 Let
  • f(n)3n3 7n2 - 4n 2 , g(n)n3
  • with n a positive integer.
  • For all n1, we have,
  • So, with n0 1, c 16 we have f(n)
    cg(n), giving, f O(g) O(n3).

13
Examples
  • Remark
  • In this example we had to use the absolute values
    because of the
  • negative term -4n in function f.
  • The inequality
  • can be obtained with repetitive use of the
    triangle inequality
  • with a,b real numbers.

14
Examples
  • Remark
  • You can prove the triangle inequality by
    considering separately all the
  • possible cases for the signs of a,b.
  • Exercise 7.2
  • Using the triangle inequality show that
  • where a,b,c,d are real numbers.
  • Can you further generalize the result ?

15
Examples
  • Example 7.4 Let f(n) be a polynomial of degree
    k, that is,
  • with n a positive integer, ak, ak-1, ,a2, a1,
    a0 real numbers and ak?0.
  • We have

16
Examples
  • With
    and n01 we
  • have f(n) cnk, giving, f O(nk).
  • In words, any polynomial function is big-O its
    leading degree without
  • the leading constant.

17
Examples
  • Remark
  • In Example 7.4, we first used a generalization of
    Exercise 7.2.
  • Then, we used the property of the absolute values
  • ab ab, for b0.
  • Then, as usual, we replaced all the terms of the
    polynomial with nk.
  • Remark
  • If ak 0 then the degree of the polynomial is
    less than k. Therefore we
  • use the constraint ak? 0 to make sure that the
    degree is indeed k.
  • It is a formality commonly used for the sake of
    accuracy.

18
Examples
  • Example 7.5
  • Let,
  • f(n) n2, g(n)5n
  • where n is a positive integer. We want to show
    that g O(f).
  • Notice that in all the previous examples we
    proved statements of the
  • form g O(f). To do that, it was sufficient to
    find a pair c, n0 such that
  • the inequality f(n) cg(n), holds for every
    n n0.
  • To prove that g is not a member of O(f) we have
    to show that such pair
  • c, n0 does not exist. In other words, for every
    pair c, n0 , there is a nn0
  • such that f(n) gt cg(n).

19
Examples
  • In this particular example we have to show that
    for every pair c, n0 there
  • exist nn0 such that n2gtc5n, or equivalently
    ngtc5.
  • We notice that any n gt max n0 , 5c will do,
    because it satisfies both
  • nn0 and ngtc5, as required.
  • Therefore, n2 O(5n).
Write a Comment
User Comments (0)
About PowerShow.com