1 / 30

CS 173: Discrete Mathematical Structures

CS 173: Discrete Mathematical Structures. Cinda Heeren heeren@cs.uiuc.edu Siebel Center, rm 2213 Office Hours: M 11a-12p. CS 173 Announcements. Hwk #11 available, due 12/3, 8a Final Exam: 12/12, 1:30-4:30p.

Download Presentation

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 Siebel Center, rm 2213 Office Hours: M 11a-12p

  2. CS 173 Announcements • Hwk #11 available, due 12/3, 8a • Final Exam: 12/12, 1:30-4:30p Cs173 - Spring 2004

  3. We understand how abstract this is. Some of us think cs125 should be a prerequisite for this course. The only algorithms you have as examples are mergesort and binary search. CS 173 Divide and Conquer Recurrences General form: T(n) = aT(n/b) + f(n) What do the algorithms look like? • Divide the problem into a subproblems of size n/b. • Solve those subproblems (recursively). • Conquer the solution in time f(n). Cs173 - Spring 2004

  4. f(n) a f(n/b) f(n/b) f(n/b) f(n/b) a a a a a f(n/b2) f(n/b2) f(n/b2) Total running time is sum of the values in the pink rectangles. We don’t have simple recipes for solving these in all cases, though sometimes we do… CS 173 Divide and Conquer Recurrences General form: T(n) = aT(n/b) + f(n) To solve a problem of size n, we require time f(n), plus the time it takes to solve a subproblems of size n/b. Cs173 - Spring 2004

  5. f(n) a f(n/b) f(n/b) f(n/b) f(n/b) a a a a a f(n/b2) f(n/b2) f(n/b2) Sum over levels… n b logbn no clue How many? CS 173 Divide and Conquer Recurrences General form: T(n) = aT(n/b) + f(n) Cs173 - Spring 2004

  6. f(n) a f(n/b) f(n/b) f(n/b) f(n/b) a a a a a f(n/b2) f(n/b2) f(n/b2) a ai i·a no clue How many blocks at level i? CS 173 Divide and Conquer Recurrences General form: T(n) = aT(n/b) + f(n) Cs173 - Spring 2004

  7. f(n) a f(n/b) f(n/b) f(n/b) f(n/b) a a a a a f(n/b2) f(n/b2) f(n/b2) n/bi n log b i·b no clue ? CS 173 Divide and Conquer Recurrences General form: T(n) = aT(n/b) + f(n) Cs173 - Spring 2004

  8. We no longer have recursive terms, but we do have a sum to deal with. a = 1, b = 2, f(n) = 1. CS 173 Divide and Conquer Recurrences General form: T(n) = aT(n/b) + f(n) Consider binary search, and write a recurrence for the # of comparisons: T(n) = T(n/2) + 1 Cs173 - Spring 2004

  9. We no longer have recursive terms, but we do have a sum to deal with. a = 2, b = 2, f(n) = n-1. CS 173 Divide and Conquer Recurrences General form: T(n) = aT(n/b) + f(n) How about our old favorite merge sort? T(n) = 2T(n/2) + n Cs173 - Spring 2004

  10. You should check that this works for the recurrences we’ve seen here. CS 173 Master Theorem The recurrence T(n) = aT(n/b) + f(n) can be solved as follows: If a·f(n/b) = kf(n) for some constant k < 1, then T(n) = (f(n)) If a·f(n/b) = Kf(n) for some constant K > 1, then T(n) = (nlogb a) If a·f(n/b) = f(n), then T(n) = (f(n)logb n) Cs173 - Spring 2004

  11. CS 173 Relations • Recall the definition of the Cartesian (Cross) Product: The Cartesian Product of sets A and B, A x B, is the set A x B = {<x,y> : xA and yB}. • A relation is just any subset of the CP!! R AxB • Ex: A = students; B = courses. R = {(a,b) | student a is enrolled in class b} Cs173 - Spring 2004

  12. Yes, a function is a special kind of relation. CS 173 Relations • Recall the definition of a function: f = {<a,b> : b = f(a) , aA and bB} • Is every function a relation? • Draw venn diagram of cross products, relations, functions Cs173 - Spring 2004

  13. CS 173 Properties of Relations • Reflexivity: A relation R on AxA is reflexive if for all aA, (a,a) R. • Symmetry: A relation R on AxA is symmetric if (x,y)  R implies (x,y)  R . Cs173 - Spring 2004

  14. CS 173 Properties of Relations • Transitivity: A relation on AxA is transitive if (a,b)  R and (b,c)  R imply (a,c)  R. • Anti-symmetry: A relation on AxA is anti-symmetric if (a,b)  R implies (b,a)  R. Cs173 - Spring 2004

  15. 1 2 3 Loops must exist on EVERY vertex. 4 CS173Properties of Relations - techniques… How can we check for the reflexive property? Draw a picture of the relation (called a “graph”). • Vertex for every element of A • Edge for every element of R Now, what’s R? {(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} Cs173 - Spring 2004

  16. 1 2 3 EVERY edge must have a return edge. 4 CS173Properties of Relations - techniques… How can we check for the symmetric property? Draw a picture of the relation (called a “graph”). • Vertex for every element of A • Edge for every element of R Now, what’s R? {(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} Cs173 - Spring 2004

  17. 1 2 3 A “short cut” must be present for EVERY path of length 2. 4 CS173Properties of Relations - techniques… How can we check for transitivity? Draw a picture of the relation (called a “graph”). • Vertex for every element of A • Edge for every element of R Now, what’s R? {(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} Cs173 - Spring 2004

  18. 1 2 3 No edge can have a return edge. 4 CS173Properties of Relations - techniques… How can we check for the anti-symmetric property? Draw a picture of the relation (called a “graph”). • Vertex for every element of A • Edge for every element of R Now, what’s R? {(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)} Cs173 - Spring 2004

  19. ? 2 1 2 1 1 ? ? 3 Yes Yes No No CS173Properties of Relations - techniques… Let R be a relation on People, R={(x,y): x and y have lived in the same country} Is R transitive? Is it symmetric? Is it reflexive? Is it anti-symmetric? Cs173 - Spring 2004

  20. Yes Definition of “divides” Is (x,z) in R? CS173Properties of Relations - techniques… Let R be a relation on positive integers, R={(x,y): 3|(x-y)} Suppose (x,y) and (y,z) are in R. Then we can write 3j = (x-y) and 3k = (y-z) Can we say 3m = (x-z)? Add prev eqn to get: 3j + 3k = (x-y) + (y-z) 3(j + k) = (x-z) Is R transitive? Cs173 - Spring 2004

  21. Yes Yes Definition of “divides” Yes, for k=0. CS173Properties of Relations - techniques… Let R be a relation on positive integers, R={(x,y): 3|(x-y)} Is (x,x) in R, for all x? Does 3k = (x-x) for some k? Is R transitive? Is it reflexive? Cs173 - Spring 2004

  22. Yes Yes Yes Definition of “divides” Yes, for k=-j. CS173Properties of Relations - techniques… Let R be a relation on positive integers, R={(x,y): 3|(x-y)} Suppose (x,y) is in R. Then 3j = (x-y) for some j. Does 3k = (y-x) for some k? Is R transitive? Is it symmetric? Is it reflexive? Cs173 - Spring 2004

  23. Yes Yes Yes No Definition of “divides” Yes, for k=-j. CS173Properties of Relations - techniques… Let R be a relation on positive integers, R={(x,y): 3|(x-y)} Suppose (x,y) is in R. Then 3j = (x-y) for some j. Does 3k = (y-x) for some k? Is R transitive? Is it symmetric? Is it reflexive? Is it anti-symmetric? Cs173 - Spring 2004

  24. No (1,1), (4,4) R’ = R U {(1,1),(4,4)} is called the reflexive closure of R. CS 173 Closure • Consider relation R={(1,2),(2,2),(3,3)} on the set A = {1,2,3,4}. • Is R reflexive? • What can we add to R to make it reflexive? Cs173 - Spring 2004

  25. P-Closure for a relation might not exist! If relation R has property P then R’ = R. CS 173 Closure • Definition: The closure of relation R on set A with respect to property P is the relation R’ with • R  R’ • R’ has property P • S with R  S and S has property P, R’  S. Cs173 - Spring 2004

  26. (a,a):  a  A We added edges! By defn CS 173 Reflexive Closure • Let r(R ) denote the reflexive closure of relation R. Then r(R ) = R U { } • Fine, but does that satisfy the definition? • R  r(R ) • r(R ) is reflexive • Need to show that for any S with particular properties, r(R )  S. Let S be such that R  S and S is reflexive. Then {(a,a):  a  A }  S (since S is reflexive) and RS (given). So, r(R )  S. Cs173 - Spring 2004

  27. (b,a): (a,b)  R We added edges! By defn CS 173 Symmetric Closure • Let s(R ) denote the symmetric closure of relation R. Then s(R ) = R U { } • Fine, but does that satisfy the definition? • R  s(R ) • s(R ) is symmetric • Need to show that for any S with particular properties, s(R )  S. Let S be such that R  S and S is symmetric. Then {(b,a): (a,b)  R }  S (since S is symmetric) and RS (given). So, s(R )  S. Cs173 - Spring 2004

  28. (a,c): b (a,b),(b,c)  R (1,3), (2,4) Which of the following is true: This set is transitive, but we added too much. This set is the transitive closure of R. This set is not transitive, one pair is missing. This set is not transitive, more than 1 pair is missing. CS 173 Transitive Closure • Let c(R ) denote the transitive closure of relation R. Then c(R ) = R U { } • Example: A={1,2,3,4}, R={(1,2),(2,3),(3,4)}. Apply definition to get: c(R ) = {(1,2),(2,3),(3,4), } Cs173 - Spring 2004

  29. 1 2 3 4 Draw a graph. “Path from a to b.” CS 173 Transitive Closure • So how DO we find the transitive closure? • Example: A={1,2,3,4}, R={(1,2),(2,3),(3,4)}. • Define a path in a relation R, on A to be a sequence of elements from A: a,x1,…xi,…xn-1,b, with (a, x1)  R, i (xi,xi+1)  R, (xn-1,b)  R. Cs173 - Spring 2004

  30. CS 173 Transitive Closure Formally: If t(R) is the transitive closure of R, and if R contains a path from a to b, then (a,b)  t(R) Notes: • Later classes will give you efficient algorithms for determining if there is a path between two vertices in a graph (graph connectivity problem) • Read about Warshall’s algorithm in the text. Cs173 - Spring 2004

More Related