1 Closures of Relations Based on Aaron Bloomfield Modified by Longin Jan Latecki Rosen, Section 8.4.

Slides:



Advertisements
Similar presentations
Coloring Warm-Up. A graph is 2-colorable iff it has no odd length cycles 1: If G has an odd-length cycle then G is not 2- colorable Proof: Let v 0, …,
Advertisements

Epp, section 10.? CS 202 Aaron Bloomfield
Some Graph Algorithms.
Representing Relations Rosen 7.3. Using Matrices For finite sets we can use zero-one matrices. Elements of each set A and B must be listed in some particular.
CSE115/ENGR160 Discrete Mathematics 04/26/12 Ming-Hsuan Yang UC Merced 1.
8.3 Representing Relations Connection Matrices Let R be a relation from A = {a 1, a 2,..., a m } to B = {b 1, b 2,..., b n }. Definition: A n m  n connection.
Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing.
CompSci 102 Discrete Math for Computer Science April 19, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Transitive Closure Theorem 1. Let R be a relation on a set A. Then R  is the transitive closure of R. the reachability relation R * of a relation R on.
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
Section 7.4: Closures of Relations Let R be a relation on a set A. We have talked about 6 properties that a relation on a set may or may not possess: reflexive,
Discussion #34 1/17 Discussion #34 Warshall’s and Floyd’s Algorithms.
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?
Applied Discrete Mathematics Week 12: Trees
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Algorithms All pairs shortest path
3/29/05Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 4.2 Minimal Spanning Trees Prepared by Amanda Dargie and Michele Fretta.
Discrete Math for CS Chapter 8: Directed Graphs. Discrete Math for CS digraph: A digraph is a graph G = (V,E) where V is a finite set of vertices and.
MATRICES. Matrices A matrix is a rectangular array of objects (usually numbers) arranged in m horizontal rows and n vertical columns. A matrix with m.
1 Representing Relations Epp section ??? CS 202 Aaron Bloomfield.
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
 Jim has six children.  Chris fights with Bob,Faye, and Eve all the time; Eve fights (besides with Chris) with Al and Di all the time; and Al and Bob.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 2 Graph Algorithms.
Properties of Relations In many applications to computer science and applied mathematics, we deal with relations on a set A rather than relations from.
Chapter 4 Relations and Digraphs
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
DISCRETE COMPUTATIONAL STRUCTURES CS Fall 2005.
Based on slides by Y. Peng University of Maryland
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.
Graphs.  Definition A simple graph G= (V, E) consists of vertices, V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局.
Rosen, Section 8.5 Equivalence Relations
The all-pairs shortest path problem (APSP) input: a directed graph G = (V, E) with edge weights goal: find a minimum weight (shortest) path between every.
Representing Relations
Relations and their Properties
Chapter 10 Graph Theory Eulerian Cycle and the property of graph theory 10.3 The important property of graph theory and its representation 10.4.
Unit – V Graph theory. Representation of Graphs Graph G (V, E,  ) V Set of vertices ESet of edges  Function that assigns vertices {v, w} to each edge.
1 Chapter Equivalence, Order, and Inductive Proof.
CSNB143 – Discrete Structure Topic 7 – Relations Part II.
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 ?
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,
Relations Section 9.1, 9.3—9.5 of Rosen Spring 2012
1 Section 4.1 Properties of Binary Relations A binary relation R over a set A is a subset of A  A. If (x, y)  R we also write x R y. Example. Some sample.
All-Pairs Shortest Paths
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.
Great Theoretical Ideas in Computer Science for Some.
COMPSCI 102 Introduction to Discrete Mathematics.
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
CS 361 – Chapter 13 Graph Review Purpose Representation Traversal Comparison with tree.
Relations and Graphs Relations and Graphs Sanjay Jain, Lecturer, School of Computing.
رياضيات متقطعة لعلوم الحاسب MATH 226. Chapter 10.
A very brief introduction to Matrix (Section 2.7) Definitions Some properties Basic matrix operations Zero-One (Boolean) matrices.
All-pairs Shortest paths Transitive Closure
Aaron Bloomfield CS 202 Rosen, section 7.4
Representing Relations
Computing Connected Components on Parallel Computers
Mathematical Structures for Computer Science Chapter 6
Closures of Relations: Transitive Closure and Partitions
Mathematics for Computer Science MIT 6.042J/18.062J
Discrete Mathematics for Computer Science
Closures of Relations Epp, section 10.1,10.2 CS 202.
Directed Graphs (Part II)
Representing Relations Using Matrices
Presentation transcript:

1 Closures of Relations Based on Aaron Bloomfield Modified by Longin Jan Latecki Rosen, Section 8.4

2 Relational closures Three types we will study –Reflexive Easy –Symmetric Easy –Transitive Hard

3 Consider a relation R: –From our MapQuest example in the last slide set –Note that it is not reflexive We want to add edges to make the relation reflexive By adding those edges, we have made a non- reflexive relation R into a reflexive relation This new relation is called the reflexive closure of R Reflexive closure

4 In order to find the reflexive closure of a relation R, we add a loop at each node that does not have one The reflexive closure of R is R U  –Where  = { (a,a) | a  R } Called the “diagonal relation” –With matrices, we set the diagonal to all 1’s

5 Rosen, section 7.4, question 1(a) Let R be a relation on the set { 0, 1, 2, 3 } containing the ordered pairs (0,1), (1,1), (1,2), (2,0), (2,2), and (3,0) What is the reflexive closure of R? We add all pairs of edges (a,a) that do not already exist We add edges: (0,0), (3,3)

6 Consider a relation R: –From our MapQuest example in the last slide set –Note that it is not symmetric We want to add edges to make the relation symmetric By adding those edges, we have made a non- symmetric relation R into a symmetric relation This new relation is called the symmetric closure of R Symmetric closure

7 In order to find the symmetric closure of a relation R, we add an edge from a to b, where there is already an edge from b to a The symmetric closure of R is R U R -1 –If R = { (a,b) | … } –Then R -1 = { (b,a) | (a,b) in R }

8 Rosen, section 8.4, question 1(b) Let R be a relation on the set { 0, 1, 2, 3 } containing the ordered pairs (0,1), (1,1), (1,2), (2,0), (2,2), and (3,0) What is the symmetric closure of R? We add all pairs of edges (a,b) where (b,a) exists –We make all “single” edges into anti-parallel pairs We add edges: (0,2), (0,3) (1,0), (2,1)

9 Paths in directed graphs A path is a sequences of connected edges from vertex a to vertex b No path exists from the noted start location A path that starts and ends at the same vertex is called a circuit or cycle –Must have length ≥ 1 Start (a) End (b) Start (a) End (b)

10 More on paths… The length of a path is the number of edges in the path, not the number of nodes

11 Shortest paths What is really needed in most applications is finding the shortest path between two vertices

12 Transitive closure The transitive closure would contain edges between all nodes reachable by a path of any length

13 Transitive closure Informal definition: If there is a path from a to b, then there should be an edge from a to b in the transitive closure First take of a definition: –In order to find the transitive closure of a relation R, we add an edge from a to c, when there are edges from a to b and b to c But there is a path from 1 to 4 with no edge! R = { (1,2), (2,3), (3,4) } (1,2) & (2,3)  (1,3) (2,3) & (3,4)  (2,4)

14 Transitive closure Informal definition: If there is a path from a to b, then there should be an edge from a to b in the transitive closure Second take of a definition: –In order to find the transitive closure of a relation R, we add an edge from a to c, when there are edges from a to b and b to c –Repeat this step until no new edges are added to the relation We will study different algorithms for determining the transitive closure red means added on the first repeat teal means added on the second repeat

15 6 degrees of separation The idea that everybody in the world is connected by six degrees of separation –Where 1 degree of separation means you know (or have met) somebody else Let R be a relation on the set of all people in the world –(a,b)  R if person a has met person b So six degrees of separation for any two people a and g means: –(a,b), (b,c), (c,d), (d,e), (e,f), (f,g) are all in R Or, (a,g)  R 6

16 Connectivity relation R contains edges between all the nodes reachable via 1 edge R◦R = R 2 contains edges between nodes that are reachable via 2 edges in R R 2 ◦R = R 3 contains edges between nodes that are reachable via 3 edges in R R n = contains edges between nodes that are reachable via n edges in R R* contains edges between nodes that are reachable via any number of edges (i.e. via any path) in R –Rephrased: R* contains all the edges between nodes a and b when is a path of length at least 1 between a and b in R R* is the transitive closure of R –The definition of a transitive closure is that there are edges between any nodes (a,b) that contain a path between them

17 R* is the star closure of relation R, and it is defined as Def.: The transitive closure of a relation R, t(R), Is the smallest transitive relation containing R. Theorem: t(R) = R*.

18 How long are the paths in a transitive closure? Let R be a relation on set A, and let A be a set with n elements –Rephrased: consider a graph G with n nodes and some number of edges Lemma 1: If there is a path (of length at least 1) from a to b in R, then there is a path between a and b of length not exceeding n Proof preparation: –Suppose there is a path from a to b in R –Let the length of that path be m –Let the path be edges (x 0, x 1 ), (x 1, x 2 ), …, (x m-1, x m ) –That’s nodes x 0, x 1, x 2, …, x m-1, x m –If a node exists twice in our path, then it’s not a shortest path As we made no progress in our path between the two occurrences of the repeated node –Thus, each node may exist at most once in the path

19 How long are the paths in a transitive closure? Proof by contradiction: –Assume there are more than n nodes in the path Thus, m > n Let m = n+1 –By the pigeonhole principle, there are n+1 nodes in the path (pigeons) and they have to fit into the n nodes in the graph (pigeonholes) –Thus, there must be at least one pigeonhole that has at least two pigeons –Rephrased: there must be at least one node in the graph that has two occurrences in the nodes of the path Not possible, as the path would not be the shortest path –Thus, it cannot be the case that m > n If there exists a path from a to b, then there is a path from a to b of at most length n

20 Finding the transitive closure Let M R be the zero-one matrix of the relation R on a set with n elements. Then the zero-one matrix of the transitive closure R* is: Nodes reachable with one application of the relation Nodes reachable with two applications of the relation Nodes reachable with n applications of the relation

21 Rosen, section 8.4, example 7 Find the zero-one matrix of the transitive closure of the relation R given by: 

22 Rosen, section 8.4, example 7  12 3

23 Transitive closure algorithm What we did (or rather, could have done): –Compute the next matrix, where 1 ≤ i ≤ n –Do a Boolean join with the previously computed matrix For our example: –Compute –Join that with to yield –Compute –Join that with from above

24 Transitive closure algorithm procedure transitive_closure (M R : zero-one n  n matrix) A := M R B := A for i := 2 to n begin A := A M R B := B  A end { B is the zero-one matrix for R* }  What is the time complexity?O(n4)O(n4)

25 Roy-Warshall Algorithm Uses only O(n 3 ) operations! Procedure Warshall (M R : rank-n 0-1 matrix) W := M R for k := 1 to n for i := 1 to n for j := 1 to n w ij := w ij  (w ik  w kj ) return W {this represents R * } w ij = 1 means there is a path from i to j going only through nodes ≤k. Indices i and j may have index higher than k.

26 Example of Roy-Warshall Algorithm Example 8 on p. 551 in Rosen’s book.