Vous êtes sur la page 1sur 39

CSE20 - Discrete Mathematics

Dr. Cynthia Bailey Lee Dr. Mia Minnes


csemoodle.ucsd.edu ted.ucsd.edu and www.math.ucsd.edu/~minnes/cse20 and minnes@math.ucsd.edu

iClicker frequency BB

Minnes (CSE20)

5/31/2013

1 / 16

Todays topics

1 2

Big-O, big-, big- notation Estimation targets HW 6 due today HW 7 due next Friday but will not be collected or graded.

Announcements:

Minnes (CSE20)

5/31/2013

2 / 16

Big-O notation

Denition: Let f : N R+ be a function. Then O (f ) is the set of all functions g such that (K > 0)(N > 0)(n N ) (g (n) Kf (n)) Implied domains: K R+ and N N

Minnes (CSE20)

5/31/2013

3 / 16

Big-O notation

Denition: Let f : N R+ be a function. Then O (f ) is the set of all functions g such that (K > 0)(N > 0)(n N ) (g (n) Kf (n)) Implied domains: K R+ and N N Idea: If g O (f ) then g is eventually bounded above by some multiple of f . Also: If g grows more slowly than f , then g O (f ).

Minnes (CSE20)

5/31/2013

3 / 16

Example
Which of these function are in the set O (f1 (n))? 1. f1 (n) = n 2. f2 (n) = 2n 3. f3 (n) = n2 4. f4 (n) = log2 (n). 5. f5 (n) = n! 6. f6 (n) = 20 7. f7 (n) = 1 f7 (n 1) + f7 (n 2) if n = 1 or n = 2 if n 3 E. 1, 3, 4

A. All of them B. None of them

C. 2, 3, 5, 7 *D. 1, 4, 6

Minnes (CSE20)

5/31/2013

4 / 16

Proving that f (n) O (f (n))

Theorem. For any function f : N R+ , f (n) O (f (n)).

Minnes (CSE20)

5/31/2013

5 / 16

Proving that f (n) O (f (n))

Theorem. For any function f : N R+ , f (n) O (f (n)). Proof. WTS (K > 0)(N > 0)(n N ) (f (n) Kf (n)) Need to nd one choice for K , N that works. Try K = 1, N = 1 WTS (n 1)(f (n) f (n)).

Minnes (CSE20)

5/31/2013

5 / 16

Proving that f (n) O (f (n))

Theorem. For any function f : N R+ , f (n) O (f (n)). Proof. WTS (K > 0)(N > 0)(n N ) (f (n) Kf (n)) Need to nd one choice for K , N that works. Try K = 1, N = 1 WTS (n 1)(f (n) f (n)). Let n N. Then f (n) = f (n) so, in particular, f (n) f (n). QED

Minnes (CSE20)

5/31/2013

5 / 16

Proving that 3f (n) O (f (n))

Theorem. For any function f : N R+ , 3f (n) O (f (n)).

Minnes (CSE20)

5/31/2013

6 / 16

Proving that 3f (n) O (f (n))

Theorem. For any function f : N R+ , 3f (n) O (f (n)). Proof. WTS (K > 0)(N > 0)(n N ) (3f (n) Kf (n)) Need to nd one choice for K , N that works. Try K = 3, N = 1 WTS (n 1)(3f (n) 3f (n)).

Minnes (CSE20)

5/31/2013

6 / 16

Proving that 3f (n) O (f (n))

Theorem. For any function f : N R+ , 3f (n) O (f (n)). Proof. WTS (K > 0)(N > 0)(n N ) (3f (n) Kf (n)) Need to nd one choice for K , N that works. Try K = 3, N = 1 WTS (n 1)(3f (n) 3f (n)). Let n N. Then 3f (n) = 3f (n) so, in particular, 3f (n) 3f (n). QED

Minnes (CSE20)

5/31/2013

6 / 16

Example 0

Let f (n) = n2 and g (n) = n. Prove that g (n) O (f (n)).

Minnes (CSE20)

5/31/2013

7 / 16

Example 0

Let f (n) = n2 and g (n) = n. Prove that g (n) O (f (n)). Is this plausible? Try n = 2: f (2) = 22 = 4 Try n = 10: f (10) = 102 = 100 g (10) = 10 g (10) < f (10) g (2) = 2 g (2) < f (2)

Minnes (CSE20)

5/31/2013

7 / 16

Example 0

Let f (n) = n2 and g (n) = n. Prove that g (n) O (f (n)). We observe that for all n 1, g (n ) = n = n 1 n n = n 2 = f (n ). Therefore, the choice K = 1, N = 1 witnesses that (K > 0)(N > 0)(n N )(g (n) Kf (n)).

Minnes (CSE20)

5/31/2013

7 / 16

Example 0
Let f (n) = n2 and g (n) = n. Prove that g (n) O (f (n)). We observe that for all n 1, g (n ) = n = n 1 n n = n 2 = f (n ). Therefore, the choice K = 1, N = 1 witnesses that (K > 0)(N > 0)(n N )(g (n) Kf (n)).

In general, if r < s then x r O (x s )

Minnes (CSE20)

5/31/2013

7 / 16

Example 1

Let f (n) = 2n2 + 1 and g (n) = 10n + 5. Prove that g (n) O (f (n)).

Minnes (CSE20)

5/31/2013

8 / 16

Example 1

Let f (n) = 2n2 + 1 and g (n) = 10n + 5. Prove that g (n) O (f (n)). Is this plausible? Try n = 2: f (2) = 2 22 + 1 = 9 Try n = 10: f (10) = 2102 +1 = 201 g (10) = 1010+5 = 105 g (10) < f (10) g (2) = 10 2 + 5 = 25 g (2) > f (2)

Minnes (CSE20)

5/31/2013

8 / 16

Example 1
Let f (n) = 2n2 + 1 and g (n) = 10n + 5. Prove that g (n) O (f (n)).
100

75

50

25

-10

-7.5

-5

-2.5

2.5

7.5

10

Intersection occurs when two functions are equal: 2n2 +1 = 10n +5 i.e. 2n2 10n 4 = 0 or, n 2 5n 2 = 0

Using quadratic formula, we see that (positive) intersection is between n = 5 and n = 6.


Minnes (CSE20) 5/31/2013 8 / 16

Example 1

Let f (n) = 2n2 + 1 and g (n) = 10n + 5. Prove that g (n) O (f (n)). Conjecture: when n 6, f (n) > g (n). That is, WTS with K = 1, N = 6, (n 6) (g (n) < f (n)) .

Minnes (CSE20)

5/31/2013

8 / 16

Example 1

Let f (n) = 2n2 + 1 and g (n) = 10n + 5. Prove that g (n) O (f (n)). Conjecture: when n 6, f (n) > g (n). That is, WTS with K = 1, N = 6, (n 6) (g (n) < f (n)) . Equivalently, WTS (n 6) (0 < f (n) g (n)).

Minnes (CSE20)

5/31/2013

8 / 16

Example 1
Let f (n) = 2n2 + 1 and g (n) = 10n + 5. Prove that g (n) O (f (n)). Conjecture: when n 6, f (n) > g (n). That is, WTS with K = 1, N = 6, (n 6) (g (n) < f (n)) . Equivalently, WTS (n 6) (0 < f (n) g (n)). By denition of these functions: f (n) g (n) = [2n2 + 1] [10n + 5] = 2n2 10n 4. This has derivative: 4n 10, which is positive for n > 3. So, the function is increasing for n > 3.

Minnes (CSE20)

5/31/2013

8 / 16

Example 1
Let f (n) = 2n2 + 1 and g (n) = 10n + 5. Prove that g (n) O (f (n)). Conjecture: when n 6, f (n) > g (n). That is, WTS with K = 1, N = 6, (n 6) (g (n) < f (n)) . Equivalently, WTS (n 6) (0 < f (n) g (n)). By denition of these functions: f (n) g (n) = [2n2 + 1] [10n + 5] = 2n2 10n 4. This has derivative: 4n 10, which is positive for n > 3. So, the function is increasing for n > 3. And, at N = 6 the LHS has value f (6) g (6) = 2 62 10 6 4 = 72 60 4 = 8 > 0.
Minnes (CSE20) 5/31/2013 8 / 16

Example 1
Let f (n) = 2n2 + 1 and g (n) = 10n + 5. Prove that g (n) O (f (n)). Conjecture: when n 6, f (n) > g (n). That is, WTS with K = 1, N = 6, (n 6) (g (n) < f (n)) . Equivalently, WTS (n 6) (0 < f (n) g (n)). By denition of these functions: f (n) g (n) = [2n2 + 1] [10n + 5] = 2n2 10n 4. This has derivative: 4n 10, which is positive for n > 3. So, the function is increasing for n > 3. And, at N = 6 the LHS has value f (6) g (6) = 2 62 10 6 4 = 72 60 4 = 8 > 0. Therefore, for all n 6, f (n) g (n) > 0.
Minnes (CSE20) 5/31/2013 8 / 16

Example 2

O (2n2 + 1) = O (5n2 ). What do we need to prove? A. 2n2 + 1 O (5n2 ) and 5n2 O (2n2 + 1). B. 2n2 + 1 = 5n2 . *C. For all f (n), f (n) O (2n2 + 1) if and only if f (n) O (5n2 ). D. For all f (n), f (n) 2n2 + 1 if and only if f (n) 5n2 . E. None of the above.

Minnes (CSE20)

5/31/2013

9 / 16

Example 2

WTS Subset inclusion O (2n2 + 1) O (5n2 ): Let g (n) O (2n2 + 1). By denition, this means that there are integers K , N such that (n N ) g (n) K (2n2 + 1)

Minnes (CSE20)

5/31/2013

10 / 16

Example 2

WTS Subset inclusion O (2n2 + 1) O (5n2 ): Let g (n) O (2n2 + 1). By denition, this means that there are integers K , N such that (n N ) g (n) 2Kn2 + K If n K then n2 K so (n max(N , K )) g (n) (2K + 1)n2

Minnes (CSE20)

5/31/2013

10 / 16

Example 2
WTS Subset inclusion O (2n2 + 1) O (5n2 ): Let g (n) O (2n2 + 1). By denition, this means that there are integers K , N such that (n N ) g (n) 2Kn2 + K If n K then n2 K so (n max(N , K )) g (n) (2K + 1)n2 Since 2K + 1 5(2K + 1), (n max(N , K )) g (n) (2K + 1)5n2

Minnes (CSE20)

5/31/2013

10 / 16

Example 2
WTS Subset inclusion O (2n2 + 1) O (5n2 ): Let g (n) O (2n2 + 1). By denition, this means that there are integers K , N such that (n N ) g (n) 2Kn2 + K If n K then n2 K so (n max(N , K )) g (n) (2K + 1)n2 Since 2K + 1 5(2K + 1), (n max(N , K )) g (n) (2K + 1)5n2 So choosing max(N , K ) and (2K + 1) proves that g (n) O (5n2 ).
Minnes (CSE20) 5/31/2013 10 / 16

Example 2

WTS Subset inclusion (in the other direction) O (5n2 ) O (2n2 + 1): Let g (n) O (5n2 ). By denition, this means that there are integers K , N such that (n N ) g (n) K (5n2 )

Minnes (CSE20)

5/31/2013

11 / 16

Example 2

WTS Subset inclusion (in the other direction) O (5n2 ) O (2n2 + 1): Let g (n) O (5n2 ). By denition, this means that there are integers K , N such that (n N ) g (n) K (5n2 ) Multiplying by 2 makes the RHS bigger (n N ) g (n) 2K (5n2 )

Minnes (CSE20)

5/31/2013

11 / 16

Example 2

WTS Subset inclusion (in the other direction) O (5n2 ) O (2n2 + 1): Let g (n) O (5n2 ). By denition, this means that there are integers K , N such that (n N ) g (n) K (5n2 ) Multiplying by 2 makes the RHS bigger (n N ) g (n) 5K (2n2 )

Minnes (CSE20)

5/31/2013

11 / 16

Example 2
WTS Subset inclusion (in the other direction) O (5n2 ) O (2n2 + 1): Let g (n) O (5n2 ). By denition, this means that there are integers K , N such that (n N ) g (n) K (5n2 ) Multiplying by 2 makes the RHS bigger (n N ) g (n) 5K (2n2 ) Adding 5K makes the RHS bigger still (n N ) g (n) 5K (2n2 ) + 5K

Minnes (CSE20)

5/31/2013

11 / 16

Example 2
WTS Subset inclusion (in the other direction) O (5n2 ) O (2n2 + 1): Let g (n) O (5n2 ). By denition, this means that there are integers K , N such that (n N ) g (n) K (5n2 ) Multiplying by 2 makes the RHS bigger (n N ) g (n) 5K (2n2 ) Adding 5K makes the RHS bigger still (n N ) g (n) 5K (2n2 + 1)

Minnes (CSE20)

5/31/2013

11 / 16

Example 2
WTS Subset inclusion (in the other direction) O (5n2 ) O (2n2 + 1): Let g (n) O (5n2 ). By denition, this means that there are integers K , N such that (n N ) g (n) K (5n2 ) Multiplying by 2 makes the RHS bigger (n N ) g (n) 5K (2n2 ) Adding 5K makes the RHS bigger still (n N ) g (n) 5K (2n2 + 1) So choosing N and 5K proves that g (n) O (2n2 + 1). Thus, g (n) g (n) O (5n2 ) g (n) O (2n2 + 1)
Minnes (CSE20) 5/31/2013 11 / 16

Other classes of functions

Denition: Let f : N R+ be a function. Then (f ) is the set of all functions g such that (K > 0)(N > 0)(n N )(g (n) Kf (n)). Implied domains: K R+ and N N Then (f ) is the set of all functions g such that (K1 > 0)(K2 > 0)(N > 0)(n N )(K1 f (n) g (n) K2 f (n)). Implied domains: K1 , K2 R+ and N N

Minnes (CSE20)

5/31/2013

12 / 16

Connections between the classes

Let f (n), g (n), h(n) be discrete functions. g (n) O (f (n)) if and only if f (n) (g (n)). g (n) (f (n)) if and only if both g (n) O (f (n)) and g (n) (f (n)). if h(n) O (g (n)) and g (n) O (f (n)) then h(n) O (f (n)).

Minnes (CSE20)

5/31/2013

13 / 16

Punchline (for polynomials)


For polynomials, f (n), O (f (n)) is determined by the leading term. For example O (n2 ) = O (3n2 5n + 100) = O (17n2 + 20n) O (n5 ) = O (5n5 60n4 ) = O (2n5 + 4n4 + 2n3 + 3n + 1)

If n 1 and a0 , . . . , an R with an = 0 then an x n + + a0 O (x n ) an x n + + a0 (x n ) an x n + + a0 (x n ) an x n + + a0 / (x m ) for m = n


Minnes (CSE20) 5/31/2013 14 / 16

Targets of estimation

Main functions that are used for benchmarks: p. 283


1 2 3 4 5 6 7 8

The constant function f (n) = 1 log2 (n) np for 0 < p < 1 n n log2 n np for 1 < p < 2n n!

Theorem: Each of these functions has a dierent class.

Minnes (CSE20)

5/31/2013

15 / 16

Illustration about relative growth rates

2000

1500

1000

500

2.5

7.5

10

12.5

15

17.5

20

Minnes (CSE20)

5/31/2013

16 / 16

Vous aimerez peut-être aussi