CS 173: Discrete Mathematical Structures

Slides:



Advertisements
Similar presentations
Chapter 3 Relations. Section 3.1 Relations and Digraphs.
Advertisements

Chap6 Relations Def 1: Let A and B be sets. A binary relation from A
Basic Properties of Relations
Representing Relations Using Matrices
8.4 Closures of Relations. Intro Consider the following example (telephone line, bus route,…) abc d Is R, defined above on the set A={a, b, c, d}, transitive?
1 Section 7.1 Relations and their properties. 2 Binary relation A binary relation is a set of ordered pairs that expresses a relationship between elements.
Relations Chapter 9.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
Applied Discrete Mathematics Week 10: Equivalence Relations
Exam 2 Review 8.2, 8.5, 8.6, Thm. 1 for 2 roots, Thm. 2 for 1 root Theorem 1: Let c 1, c 2 be elements of the real numbers. Suppose r 2 -c 1.
Relation. 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  A.
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
1 Relations Rosen 6 th ed., § Relations Re lationships between elements of sets occur in many contextsRe lationships between elements of sets occur.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Discrete Math for CS Binary Relation: A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation.
Chapter 9. Section 9.1 Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and.
8.3 Representing Relations Directed Graphs –Vertex –Arc (directed edge) –Initial vertex –Terminal vertex.
1 Closures of Relations: Transitive Closure and Partitions Sections 8.4 and 8.5.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局.
Lecture 4.4: Equivalence Classes and Partially Ordered Sets CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda.
Relations and their Properties
Lecture 4.3: Closures and Equivalence Relations CS 250, Discrete Structures, Fall 2013 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.
Discrete Mathematics Lecture # 15 Types of Relations (contd.)
Relation. Combining Relations Because relations from A to B are subsets of A x B, two relations from A to B can be combined in any way two sets can be.
Problem Statement How do we represent relationship between two related elements ?
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Lecture 4.1: Relations Basics CS 250, Discrete Structures, Fall 2012 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.
Lecture 4.2: Relations Basics CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
Representing Relations Using Matrices A relation between finite sets can be represented using a zero-one matrix Suppose R is a relation from A = {a 1,
Chapter Relations and Their Properties
Relations Section 9.1, 9.3—9.5 of Rosen Spring 2012
Lecture 4.2: Relations CS 250, Discrete Structures, Fall 2013 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
8.4 Closures of Relations Definition: The closure of a relation R with respect to property P is the relation obtained by adding the minimum number of.
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
Lecture 4.4: Equivalence Classes and Partially Ordered Sets CS 250, Discrete Structures, Fall 2012 Nitesh Saxena Adopted from previous lectures by Cinda.
Lecture 4.1: Relations Basics CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren.
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
Section 9.1. Section Summary Relations and Functions Properties of Relations Reflexive Relations Symmetric and Antisymmetric Relations Transitive Relations.
Chapter8 Relations 8.1: Relations and their properties.
Binary Relation: A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation is a relation on.
Relations Chapter 9 Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill.
Representing Relations Using Digraphs
Discrete Mathematical
Relations and Their Properties
Relations.
Relations Binary relations represent relationships between the elements of two sets. A binary relation R from set A to set B is defined by: R  A 
Equivalence Relations
Relations Chapter 9.
Lecture # 14 Types of Relations
Applied Discrete Mathematics Week 10: Relations
Representing Relations
Dr. Ameria Eldosoky Discrete mathematics
Lecture 4.1: Relations Basics
CSE115/ENGR160 Discrete Mathematics 04/28/11
CSNB 143 Discrete Mathematical Structures
Lecture 4.3: Closures and Equivalence Relations
Applied Discrete Mathematics Week 10: Equivalence Relations
8.5 Equivalence Relations
Lecture 4.1: Relations Basics
Relations.
Closures of Relations: Transitive Closure and Partitions
Relations and Digraphs
CS 250, Discrete Structures, Fall 2014
CS 250, Discrete Structures, Fall 2015
Lecture 4.3: Closures and Equivalence Relations
MCS680: Foundations Of Computer Science
Lecture 4.1: Relations Basics
Properties of Relations
Chapter 8 (Part 2): Relations
Presentation transcript:

CS 173: Discrete Mathematical Structures Cinda Heeren heeren@cs.uiuc.edu Siebel Center, rm 2213 Office Hours: W 12:30-2:30

CS 173 Announcements Homework #11 available, due 12/04, 8a. Final exam 12/14, 8-11a. Email Cinda with conflicts. Exam 2 returned in section. If you have no section, see me. Exam 2 avg: 58, so I’m giving you 15% on the exam, or 3 class points. Cs173 - Spring 2004

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). 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. Cs173 - Spring 2004

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) You should check that this works for the recurrences we’ve seen here. Cs173 - Spring 2004

A x B = {<x,y> : xA and yB}. 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

CS 173 Relations Yes, a function is a special kind of relation. 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 Yes, a function is a special kind of relation. Cs173 - Spring 2004

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

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

CS173 Properties 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)} 1 2 3 4 A “short cut” must be present for EVERY path of length 2. Cs173 - Spring 2004

CS173 Properties 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)} 1 2 3 4 Loops must exist on EVERY vertex. Cs173 - Spring 2004

CS173 Properties 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)} 1 2 3 4 EVERY edge must have a return edge. Cs173 - Spring 2004

CS173 Properties 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)} 1 2 3 4 No edge can have a return edge. Cs173 - Spring 2004

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

CS173 Properties 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. Definition of “divides” Then we can write 3j = (x-y) and 3k = (y-z) Can we say 3m = (x-z)? Is (x,z) in R? Add prev eqn to get: 3j + 3k = (x-y) + (y-z) 3(j + k) = (x-z) Is R transitive? Yes Cs173 - Spring 2004

CS173 Properties 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? Definition of “divides” Does 3k = (x-x) for some k? Yes, for k=0. Is R transitive? Yes Is it reflexive? Yes Cs173 - Spring 2004

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

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

CS173 More than one relation Suppose we have 2 relations, R1 and R2, and recall that relations are just sets! So we can take unions, intersections, complements, symmetric differences, etc. There are other things we can do as well… Cs173 - Spring 2004

CS173 More than one relation Let R be a relation from A to B (R  AxB), and let S be a relation from B to C (S  BxC). The composition of R and S is the relation from A to C (SR  AxC): SR = {(a,c):  bB, (a,b)  R, (b,c)  S} A B C 1 2 3 4 x y z s t u v R S SR = {(1,u),(1,v),(2,t),(3,t),(4,u)} Cs173 - Spring 2004

CS173 More than one relation Let R be a relation on A. Inductively define R1 = R Rn+1 = Rn  R A A A R R1 1 1 1 2 2 2 3 3 3 4 4 4 R2 = R1R = {(1,1),(1,2),(1,3),(2,3),(3,3),(4,1), (4,2)} Cs173 - Spring 2004

CS173 More than one relation Let R be a relation on A. Inductively define R1 = R Rn+1 = Rn  R A A A R R2 1 1 1 2 2 2 3 3 3 … = R4 = R5 = R6… 4 4 4 R3 = R2R = {(1,1),(1,2),(1,3),(2,3),(3,3),(4,1),(4,2),(4,3)} Cs173 - Spring 2004

CS173 Relations - A Theorem: If R is a transitive relation, then Rn  R, n. Aside: notice that this theorem allows us to conclude that the previous relation was NOT transitive. Recall: “if p then q”  “if not q then not p.” We saw that Rn was not a subset of R (it was growing on every iteration). Therefore, R is not transitive. Cs173 - Spring 2004

CS173 Relations - A Theorem: If R is a transitive relation, then Rn  R, n. Proof by induction on n. Base case (n=1): R1  R because by definition, R1 = R. IH: if R is transitive, then Rn  R. Prove: if R is transitive, then Rn+1  R. Typical way of proving subset. We are trying to prove that Rn+1  R. To do this, we select an element of Rn+1 and show that it is also an element of R. Let (a,b) be an element of Rn+1. Since Rn+1 = Rn  R, we know there is an x so that (a,x)  R and (x,b)  Rn. By IH, since Rn  R, (x,b)  R. But wait, if (a,x)  R, and (x,b)  R, and R is transitive, then (a,b)  R. Cs173 - Spring 2004

CS173 Relations - more techniques… Suppose we have our old relation R on AxB, where A={1,2,3,4}, and B={u,v,w}, R={(1,u),(1,v),(2,w),(3,w),(4,u)}. Then we can represent R as: The labels on the outside are for clarity. It’s really the matrix in the middle that’s important. u v w 1 2 3 4 This is a |A| x |B| matrix whose entries indicate membership in R. For a general description, see Rosen pg. 490. Cs173 - Spring 2004

CS173 Relations - more techniques… Some things to think about. Let R be a relation on a set A, and let MR be the matrix representation of R. Then R is reflexive if, ______________. All entries in MR are 1. The \ diagonal of MR contains only 1s. The first column of MR contains no 0s. None of the above. u v w 1 Cs173 - Spring 2004

CS173 Relations - more techniques… Some things to think about. Let R be a relation on a set A, and let MR be the matrix representation of R. Then R is symmetric if, ______________. All entries above the \ are 1. The first and last columns of MR contain an equal # of 0s. MR is visually symmetric about the \ diagonal. None of the above. u v w 1 Cs173 - Spring 2004

CS173 Relations - more techniques… Suppose we have R1 and R2 defined on A: R1 u v w 1 R2 u v w 1 1 Then R1  R2 is the bitwise “or” of the entries: MR1R2 = MR1 v MR2 1 Then R1  R2 is the bitwise “and” of the entries: MR1R2 = MR1  MR2 Cs173 - Spring 2004

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? No What can we add to R to make it reflexive? (1,1), (4,4) R’ = R U {(1,1),(4,4)} is called the reflexive closure of R. Cs173 - Spring 2004

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. P-Closure for a relation might not exist! If relation R has property P then R’ = R. Cs173 - Spring 2004

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. (a,a):  a  A We added edges! By defn Cs173 - Spring 2004

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. (b,a): (a,b)  R We added edges! By defn Cs173 - Spring 2004

CS 173 Transitive Closure Let c(R ) denote the transitive closure of relation R. Then c(R ) = R U { } (a,c): b (a,b),(b,c)  R 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), } (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. Cs173 - Spring 2004

CS 173 Transitive Closure So how DO we find the transitive closure? Draw a graph. Example: A={1,2,3,4}, R={(1,2),(2,3),(3,4)}. 1 2 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 “Path from a to b.”

CS 173 Transitive Closure Formally: Notes: 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

CS 173 Equivalence Relations Example: Let S = {people in this classroom}, and let R = {(a,b): a has same # of coins in his/her bag as b} Quiz time: Is R reflexive? Is R symmetric? Is R transitive? This is a special kind of relation, characterized by the properties it has. What’s special about it? Yes Everyone with the same # of coins as you is just like you. Yes Yes Cs173 - Spring 2004

CS 173 Equivalence Relations Formally: Relation R on A is an equivalence relation if R is Reflexive ( a  A, aRa) Symmetric (aRb --> bRa) Transitive (aRb ^ bRc --> aRc) “What the heck is aRb?” aRb denotes (a,b)  R. Example: S = Z (integers), R = {(a,b) : a  b mod 4} Is this relation an equivalence relation on S? Have to PROVE reflexive, symmetric, transitive. a%4 = b? Cs173 - Spring 2004

CS 173 Equivalence Relations Example: S = Z (integers), R = {(a,b) : a  b mod 4} Is this relation an equivalence relation on S? Start by thinking of R a different way: aRb iff there is an int k so that a = 4k + b. Your quest becomes one of finding ks. Let a be any integer. aRa since a = 40 + a. Consider aRb. Then a = 4k + b. But b = -4k + a. Consider aRb and bRc. Then a = 4k + b and b = 4j + c. So, a = 4k + 4j +c = 4(k+j) + c. Cs173 - Spring 2004

CS 173 Equivalence Relations Example: S = people in this room, R = {(a,b) : total $ on a is within $1.00 of total $ on b} Is this relation an equivalence relation on S? Clearly reflexive and symmetric. Is it transitive? Yes, I can give a proof. Yes, I think so, but I can’t prove it. No, I can give a proof. No, I don’t think so, but I can’t prove it. Cs173 - Spring 2004

CS 173 Equivalence Classes Example: Back to coins in bags. Definition: Let R be an equivalence relation on S. The equivalence class of a  S, [a]R, is [a]R = {b: aRb} a is just a name for the equiv class. Any member of the class is a representative. Cs173 - Spring 2004

CS 173 Equivalence Classes What equivalence relation we’ve seen recently has representatives [244], [7], [58], [1]? Cs173 - Spring 2004