1 / 37

CS 173: Discrete Mathematical Structures

CS 173: Discrete Mathematical Structures. Cinda Heeren heeren@cs.uiuc.edu Rm 2213 Siebel Center Office Hours: W 9:30-11:30a. CS 173 Announcements. Homework 4 available. Due 02/12, 8a. Midterm 1: 2/23/06, 7-9p, location SC 1404. Michael Tito Janet Cindy Bobby. Katherine Scruse

tovi
Télécharger la présentation

CS 173: Discrete Mathematical Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 173:Discrete Mathematical Structures Cinda Heeren heeren@cs.uiuc.edu Rm 2213 Siebel Center Office Hours: W 9:30-11:30a

  2. CS 173 Announcements • Homework 4 available. Due 02/12, 8a. • Midterm 1: 2/23/06, 7-9p, location SC 1404. Cs173 - Spring 2004

  3. Michael Tito Janet Cindy Bobby Katherine Scruse Carol Brady Mother Teresa CS 173 Functions - misc. properties • f() =  • f({a}) = {f(a)} • f(A U B) = f(A) U f(B) • f(A  B)  f(A)  f(B) Cs173 - Spring 2004

  4. CS 173 Functions - misc. properties f(A  B)  f(A)  f(B)? Choose an arbitrary b  f(A  B), and show that it must also be an element of f(A)  f(B). f(A  B) = {x : a  (A  B), f(a) = x} So, a  (A  B) such that f(a) = b. If a  A (it is), then f(a) = b  f(A). If a  B (it is), then f(a) = b  f(B). b  f(A), and b  f(B), so b  f(A)  f(B). Cs173 - Spring 2004

  5. Michael Tito Janet Cindy Bobby Katherine Scruse Carol Brady Mother Teresa CS 173 Functions - misc. properties • f-1() =  • f-1(A U B) = f-1(A) U f-1(B) • f-1(A  B) = f-1(A)  f-1(B) Cs173 - Spring 2004

  6. Michael Tito Janet Cindy Bobby Katherine Scruse Carol Brady Mother Teresa Not one-to-one Every b  B has at most 1 preimage. CS 173 Functions - injection A function f: A  B is one-to-one (injective, an injection) if a,b,c, (f(a) = b  f(c) = b)  a = c Cs173 - Spring 2004

  7. Michael Tito Janet Cindy Bobby Katherine Scruse Carol Brady Mother Teresa Not onto Every b  B has at least 1 preimage. CS 173 Functions - surjection A function f: A  B is onto (surjective, a surjection) if b  B, a  A f(a) = b Cs173 - Spring 2004

  8. Isaak Bri Lynette Aidan Evan Isaak Bri Lynette Aidan Evan Cinda Dee Deb Katrina Dawn Cinda Dee Deb Katrina Dawn Every b  B has exactly 1 preimage. An important implication of this characteristic: The preimage (f-1) is a function! CS 173 Functions - bijection A function f: A  B is bijective if it is one-to-one and onto. Cs173 - Spring 2004

  9. yes yes yes CS 173 Functions - examples Suppose f: R+  R+, f(x) = x2. Is f one-to-one? Is f onto? Is f bijective? Cs173 - Spring 2004

  10. no yes no CS 173 Functions - examples Suppose f: R  R+, f(x) = x2. Is f one-to-one? Is f onto? Is f bijective? Cs173 - Spring 2004

  11. no no no CS 173 Functions - examples Suppose f: R  R, f(x) = x2. Is f one-to-one? Is f onto? Is f bijective? Cs173 - Spring 2004

  12. CS 173 Functions - composition Let f:AB, and g:BC be functions. Then the composition of f and g is: (g o f)(x) = g(f(x)) Cs173 - Spring 2004

  13. CS 173 Functions - a little problem Let f:AB, and g:BC be functions. Prove that if f and g are one to one, then g o f :AC is one to one. Recall defn of one to one: f:A->B is 1to1 if f(a)=b and f(c)=b --> a=c. Suppose g(f(x)) = y and g(f(w)) = y. Show that x=w. f(x) = f(w) since g is 1 to 1. Then x = w since f is 1 to 1. Cs173 - Spring 2004

  14. CS 173 Functions - another Let f:AB, and g:BC be functions. Prove that if f and g are onto, then g o f :AC is onto. Cs173 - Spring 2004

  15. In this course, log2 n is written lg n. If we write log n, assume log2 n. CS 173 Familiar functions Polynomials: f(x) = a0xn + a1xn-1 + … + an-1x1 + anx0 Ex: f(x) = x3 - 2x2 + 15 Exponentials: f(x) = cdx Ex: f(x) = 310x, f(x) = ex Logarithms: log2 x = y, where 2y = x. Cs173 - Spring 2004

  16. 0 CS 173 Familiar functions Ceiling: f(x) = x the least integer y so that x  y. Ex: 1.2 = 2; -1.2 = -1; 1 = 1 Floor: f(x) = x the greatest integer y so that x  y. Ex: 1.8 = 1; -1.8 = -2; -5 = -5 Quiz: what is -1.2 + 1.1 ? Cs173 - Spring 2004

  17. In this case our algorithm takes about n time units. We say the algorithm has “order n” running time. CS 173 Two example algorithms. Suppose we wish to find the maximum number in a sequence of n numbers. How long should we spend doing this? Suppose it takes 1 time unit to make a comparison between two numbers. We really have no clue how long the algorithm takes to run, but we have an inkling that it depends linearly on n. Cs173 - Spring 2004

  18. In this case the algorithm takes about lg n time units. We say the algorithm has “order log n” running time. CS 173 Two example algorithms. I have a number between 0 and 63. You ask a question, I’ll tell you yes or no. How long will it take you to find my secret number? Suppose it takes 1 time unit to answer a query about my number. We really have no clue how long the algorithm takes to run, but we have an inkling that it depends logarithmically on n. Cs173 - Spring 2004

  19. Who is the tortoise? Who is the hare? How would you describe blue’s performance? At each distance, who wins? CS 173 Who wins the race? The following graph gives times for completing races of length x, for 4 different competitors. time distance Cs173 - Spring 2004

  20. Every unit increase in x results in the same increase in f(x). Linear functions CS 173 Quiz time… Describe these functions: f(x) x Cs173 - Spring 2004

  21. Very slow growing. Logarithmic function CS 173 Quiz time… Describe this function: Cs173 - Spring 2004

  22. Very fast growing. Exponential function CS 173 Quiz time… Describe this function: Cs173 - Spring 2004

  23. Polynomial Quadratic function CS 173 Quiz time… Describe this function: f(x) x Cs173 - Spring 2004

  24. CS 173 Growth of functions Algorithm analysis is concerned with: • Type of function that describes run time (we ignore constant factors since different machines have different speed/cycle) • Large values of x Cs173 - Spring 2004

  25. We say “f(x) is big O of g(x)” Recipe for proving f(x) = O(g(x)): find a c and k so that the inequality holds. CS 173 Growth of functions Important definition: For functions f and g we write f(x) = O(g(x)) to denote  c,k so that  x>k, f(x)  c·g(x) Cs173 - Spring 2004

  26. c·g(x) g(x) We give an eventual upper bound on f(x) k CS 173 Growth of functions f(x) = O(g(x)) iff  c,k so that  x>k, f(x)  c·g(x) f(x) x Cs173 - Spring 2004

  27. There’s k There’s c CS 173 Growth of functions (examples) f(x) = O(g(x)) iff  c,k so that  x>k, f(x)  c·g(x) 3n = O(15n) since  n>0, 3n  1·15n Cs173 - Spring 2004

  28. 5 8 0 5 CS 173 Growth of functions (examples) f(x) = O(g(x)) iff  c,k so that  x>k, f(x)  c·g(x) 15n = O(3n) since  n>__, 15n  __·3n Cs173 - Spring 2004

  29. 1 CS 173 Growth of functions (examples) f(x) = O(g(x)) iff  c,k so that  x>k, f(x)  c·g(x) x2 = O(x3) since  x> __, x2  x3 Cs173 - Spring 2004

  30. 0 1000 CS 173 Growth of functions (examples) f(x) = O(g(x)) iff  c,k so that  x>k, f(x)  c·g(x) 1000x2 = O(x2) since  x> __, 1000x2  ____·x2 Cs173 - Spring 2004

  31. 100x  100x2 100  100x2 k = 1, c = 20100 CS 173 Growth of functions (examples) f(x) = O(g(x)) iff  c,k so that  x>k, f(x)  c·g(x) Prove that x2 + 100x + 100 = O((1/100)x2) x2 + 100x + 100  201x2 when x > 1  20100·(1/100)x2 Cs173 - Spring 2004

  32. Nothing works for k Try c = 10 k = 200, c = 11 Similar problem, different technique. Try c = 11 200 CS 173 Growth of functions (examples) Prove that 5x + 100 = O(x/2) Need  x> ___, 5x + 100  ___ · x/2  x> ___, 5x + 100  10 · x/2  x> ___, 5x + 100  5x + x/2  x> ___, 100  x/2 Cs173 - Spring 2004

  33. CS173Growth of functions Guidelines: • In general, only the largest term in a sum matters. a0xn + a1xn-1 + … + an-1x1 + anx0 = O(xn) • n dominates lg n. n5lg n = O(n6) • List of common functions in increasing O() order: 1 n (n lg n) n2 n3 … 2n n! Cs173 - Spring 2004

  34. Questions? CS173Growth of functions (more examples) • So Cs173 - Spring 2004

  35. c = c1+c2, k = max{k1,k2} CS173Growth of functions - a theorem If f1(x) = O(g1(x)) and f2(x)=O(g2(x)), then f1(x) + f2(x) = O(max{g1(x),g2(x)}) Proof: Let h(x) = max{g1(x),g2(x)})… Need to find constants c and k so that x>k, f1(x) + f2(x)  c•h(x). Know f1(x) c1• g1(x) and f2(x) c2• g2(x). So, f1(x) + f2(x)  c1•g1(x) + c2•g2(x)  c1•h(x) + c2•h(x) = (c1+c2)•h(x) Cs173 - Spring 2004

  36. This is just the case where g1(x) = g2(x) = g(x) CS173Growth of functions - a corollary We know: If f1(x) = O(g1(x)) and f2(x)=O(g2(x)), then f1(x) + f2(x) = O(max{g1(x),g2(x)}) Corollary: If f1(x) = O(g(x)) and f2(x)=O(g(x)), then f1(x) + f2(x) = O(g(x)). Cs173 - Spring 2004

  37. CS173Growth of functions - another theorem If f1(x) = O(g1(x)) and f2(x)=O(g2(x)), then f1(x)·f2(x) = O(g1(x)·g2(x)) Proof: Cs173 - Spring 2004

More Related