Closures of Relations: Transitive Closure and Partitions

Slides:



Advertisements
Similar presentations
Epp, section 10.? CS 202 Aaron Bloomfield
Advertisements

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.
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?
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.
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
Dynamic Programming – Part 2 Introduction to Algorithms Dynamic Programming – Part 2 CSE 680 Prof. Roger Crawfis.
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.
Graph Theoretic Concepts. What is a graph? A set of vertices (or nodes) linked by edges Mathematically, we often write G = (V,E)  V: set of vertices,
Chapter 4 Relations and Digraphs
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Relations and Their Properties
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.
DISCRETE COMPUTATIONAL STRUCTURES CS Fall 2005.
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 歐亞書局.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Relations and their Properties
Relations. Important Definitions We covered all of these definitions on the board on Monday, November 7 th. Definition 1 Definition 2 Definition 3 Definition.
1 Chapter Equivalence, Order, and Inductive Proof.
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.
Relations Section 9.1, 9.3—9.5 of Rosen Spring 2012
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Chapter 8: Relations. 8.1 Relations and Their Properties Binary relations: Let A and B be any two sets. A binary relation R from A to B, written R : A.
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.
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
Relations and Functions ORDERED PAIRS AND CARTESIAN PRODUCT An ordered pair consists of two elements, say a and b, in which one of them, say a is designated.
1 Closures of Relations Based on Aaron Bloomfield Modified by Longin Jan Latecki Rosen, Section 8.4.
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
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 
Relations Chapter 9.
Aaron Bloomfield CS 202 Rosen, section 7.4
Chapter 9 (Part 2): Graphs
Representing Relations
Relations Rosen 5th ed., ch. 7.
CS 173: Discrete Mathematical Structures
Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by recurrences with overlapping subproblems.
Dynamic Programming Dynamic Programming is a general algorithm design technique for solving problems defined by recurrences with overlapping subproblems.
Chapter 8 Dynamic Programming
CSNB 143 Discrete Mathematical Structures
Lecture 4.3: Closures and Equivalence Relations
Mathematical Structures for Computer Science Chapter 6
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 9 Relations Slides are adopted from.
Discrete Math (2) Haiming Chen Associate Professor, PhD
Applied Discrete Mathematics Week 10: Equivalence Relations
Based on slides by Y. Peng University of Maryland
Relations.
Chapter 8 Dynamic Programming
Lecture 4.3: Closures and Equivalence Relations
교환 학생 프로그램 내년 1월 중순부터 6월 초 현재 학부 2,3 학년?
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
Closures of Relations Epp, section 10.1,10.2 CS 202.
Chapter 8 (Part 2): Relations
Representing Relations Using Matrices
Presentation transcript:

Closures of Relations: Transitive Closure and Partitions Sunday, December 09, 2018 Closures of Relations: Transitive Closure and Partitions Sections 8.4 and 8.5 © 2006 by A-H. Esfahanian. All Rights Reserved.

Concept of “closure” The natural numbers N (counting numbers) are not closed under subtraction: when we close them under subtraction, we get Z, the integers (positive and negative). When we close Z under the operation of division, we get Q, the rational numbers. “Closing” a relation has important applications.

Sunday, December 09, 2018 Transitive closure Computing the transitive closure of a digraph is an important problem in many computer science applications: Evaluation of recursive database queries. Analysis of reachability (connectivity) of transition graphs in communication networks. Construction of parsing automata in compilers. 3 © 2006 by A-H. Esfahanian. All Rights Reserved. 3

Introduction Closure of relation properties Sunday, December 09, 2018 Introduction Closure of relation properties When a property does not hold for a relation, how could we minimally augment the relation so that the property would hold? © 2006 by A-H. Esfahanian. All Rights Reserved.

Reflexive Closure Example: Consider the relation Sunday, December 09, 2018 Reflexive Closure Example: Consider the relation R = {(1,1), (1,2), (2,1), (3,2)} on set {1,2,3} Is it reflexive? How can we produce a reflective relation containing R that is as small as possible? © 2006 by A-H. Esfahanian. All Rights Reserved.

Reflexive Closure – cont. Sunday, December 09, 2018 Reflexive Closure – cont. When a relation R on a set A is not reflexive: How to minimally augment R (adding the minimum number of ordered pairs) to make it a reflexive relation? The reflexive closure of R. The reflexive closure of R can be formed by adding all of the pairs of the form (a,a) to R. In other words we should find: R = { (1,1), (1,2), (2,1), (3,2) } U { (1,1), (2,2), (3,3) } © 2006 by A-H. Esfahanian. All Rights Reserved.

Reflexive Closure – Cont. Sunday, December 09, 2018 Reflexive Closure – Cont. The diagonal relation on A is:  = {(a,a) | a  A}. The reflexive closure of R is then: R  . Properties: R  (R  ); R   is reflexive;  S (R  S  S is reflexive)  (R  )  S. In zero-one matrix notation: MR  M Turn on all the diagonal bits! © 2006 by A-H. Esfahanian. All Rights Reserved.

Example Consider R = {(a,b)ZZ | a < b} Sunday, December 09, 2018 Example Consider R = {(a,b)ZZ | a < b} The reflexive closure of relation R is: R   = {(a,b)ZZ | a < b}  {(a,a) | a Z} = {(a,b)ZZ | a  b} © 2006 by A-H. Esfahanian. All Rights Reserved.

Symmetric Closure (optional) Sunday, December 09, 2018 Symmetric Closure (optional) Example: Consider R ={(1,1), (1,2), (2,2), (2,3), (3,1), (3,2)} R is not symmetric; the pairs missing are: (2,1), (1,3). If we add those, we obtain the new relation: {(1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1), (3,2)}. The new relation is symmetric. © 2006 by A-H. Esfahanian. All Rights Reserved.

Symmetric Closure (optional) Sunday, December 09, 2018 Symmetric Closure (optional) When a relation R on a set A is not symmetric: How to minimally augment R (adding the minimum number of ordered pairs) to have a symmetric relation? The symmetric closure of R. © 2006 by A-H. Esfahanian. All Rights Reserved.

Symmetric Closure (optional) Sunday, December 09, 2018 Symmetric Closure (optional) The inverse of R is: R-1 = {(b,a) | (a, b)  R}. The symmetric closure of R is then: R  R-1. Properties: R  (R  R-1); R  R-1 is symmetric;  S (R  S  S is symmetric)  (R  R-1)  S. In zero-one matrix notation: MR  MRt © 2006 by A-H. Esfahanian. All Rights Reserved.

Example (optional) Consider R = {(a,b)ZZ | a < b} Sunday, December 09, 2018 Example (optional) Consider R = {(a,b)ZZ | a < b} The symmetric closure of relation R is: R  R-1 = {(a,b)ZZ | a < b}  {(a,b)ZZ | b < a} = {(a,b)ZZ | a  b} © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closures Consider R = {(1,3), (1,4), (2,1), (3,2)}. Sunday, December 09, 2018 Transitive Closures Consider R = {(1,3), (1,4), (2,1), (3,2)}. R is not transitive; What are the missing terms? Few are: (1,2), (2,3), (2,4), (3,1). If we add those, we obtain the new relation: {(1,2), (1,3), (1,4), (2,1), (2,3), (2,4), (3,1), (3,2)}. Is the above relation transitive? No, it is not. Missing terms such as (1,1), (2,2)… Transitive closure is more complicated to build. © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure When a relation R on a set A is not transitive: Sunday, December 09, 2018 Transitive Closure When a relation R on a set A is not transitive: How to minimally augment R (adding the minimum number of ordered pairs) to have a transitive relation? The transitive closure of R. © 2006 by A-H. Esfahanian. All Rights Reserved.

Paths in Directed Graphs Sunday, December 09, 2018 Paths in Directed Graphs Definition: A path from a to b in a digraph G is a sequence of 1 or more adjacent arcs (a,x1), (x1,x2), (x2,x3), …, (xn-1, b). Denoted: a, x1, x2, x3, …, xn-1, b Has length n. If a = b, the path is called a circuit or a cycle, since the path returns to its start. Does a path appear to be “transitive”? © 2006 by A-H. Esfahanian. All Rights Reserved.

Example  a path of length 2 from 1 to 2: arcs (1,3), (3,2). Sunday, December 09, 2018 Example  a path of length 2 from 1 to 2: arcs (1,3), (3,2).  a path of length 3 from 3 to 4: (3,2), (2,1), (1,4). There are no paths from 4 to 1 4 to 2 4 to 3 1 2 4 3 © 2006 by A-H. Esfahanian. All Rights Reserved.

Sunday, December 09, 2018 Paths in Relations There is a path from a to b in R if there is a sequence of elements: x1, x2, …, xn-1 with (a,x1)R, (x1,x2)R, …, (xn-1, b)R. Example. R = {(1,3), (1,4), (2,1), (3,2)}  a path in R (len. 2) from 1 to 2: (1,3), (3,2)R.  a path in R (len. 3) from 3 to 4: (3,2), (2,1), (1,4)R. There is no path in R from 4 to 1, nor to 2, nor to 3. © 2006 by A-H. Esfahanian. All Rights Reserved.

Theorem 1 Theorem: Let R be a relation on a set A. Sunday, December 09, 2018 Theorem 1 Theorem: Let R be a relation on a set A.  a path in R of length n from a to b  (a,b) Rn. Proof © 2006 by A-H. Esfahanian. All Rights Reserved.

R* ={(a,b) |  a path in R from a to b}. Sunday, December 09, 2018 Transitive Closure Definition: Let R be a relation on a set A. The connectivity relation is the relation R* defined as: R* ={(a,b) |  a path in R from a to b}. From the above definition of R* and the previous theorem, R* can be written as: R* = k=1 Rk. We used this notion of “connectivity” in the graphics Fill algorithm. Also, we used it the airplane flights example. © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure – Cont. Sunday, December 09, 2018 Transitive Closure – Cont. Theorem 2 The transitive closure of R is R*. Proof: R  R*, because if there is an edge from a to b then there is a path from a to b. R* is transitive, because if  a path from a to b and  a path from b to c then  a path from a to c. S (R  S  S is transitive)  R*  S. Proof. Let S be a transitive relation, and assume RS. So R* S* because RS. Also k Sk  S, because S is transitive (see last theorem of sect. 6.1) SoS*  S. Therefore, R* S. © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure – Cont. Sunday, December 09, 2018 Transitive Closure – Cont. Lemma: Let A be a set with n elements, and R be a relation on A. If there is a path in R from a to b (with ab), then there is such a path with length  n-1. R* = R  R2  R3  …  Rn. © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure – Cont. Sunday, December 09, 2018 Transitive Closure – Cont. Theorem: Let MR be the zero-one matrix of relation R on a set with n elements. The zero-one matrix of the transitive closure R* is: MR* = MR  MR[2]  MR[3]  …  MR[n]. © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure - Example Sunday, December 09, 2018 Transitive Closure - Example Find the matrix MR* of the transitive closure of R: MR = Solution: MR[2] = MR[3] = MR*= MRMR[2]MR[3] = 3 1 2 © 2006 by A-H. Esfahanian. All Rights Reserved.

Algorithm 1 for TC Procedure for computing transitive closure: A = MR; Sunday, December 09, 2018 Algorithm 1 for TC Procedure for computing transitive closure: A = MR; B = A; For i=2 to n do the following: A = A o MR; // Boolean product B = B  A; // Join operation © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure - Example Sunday, December 09, 2018 Transitive Closure - Example Find the matrix MR* of the transitive closure of R: MR = Solution: B1= A1= MR = Ak=Ak-1o MR Bk=Bk-1Ak A2=MR[2]= B2= A3=MR[3]= MR*=B3= 3 1 2 © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure – optional Sunday, December 09, 2018 Transitive Closure – optional Toward a more efficient algorithm (Warshall’s) Definition: Let R be a relation on S={v1,v2,…, vn}. The interior vertices of a path of length m from a to b: a, x1, x2, x3, …, xm-1, b are: x1, x2, x3, …, xm-1. © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure – optional Sunday, December 09, 2018 Transitive Closure – optional Warshall’s Alg. iteratively constructs 0-1 matrices: W0 = MR; W1=[w[1]ij], where w[1]ij=1   a path from vi to vj with interior vertices in {v1}; W2=[w[2]ij], where w[2]ij=1   a path from vi to vj with interior vertices in {v1,v2}… Wk=[w[k]ij], where w[k]ij=1   a path from vi to vj with interior vertices in {v1,v2, …, vk}… MR* = Wn. © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure - Example Sunday, December 09, 2018 Transitive Closure - Example Find the matrix MR* of the transitive closure of R: MR = Solution: W0 = MR W1 = W2 = MR* = W3 = 3 1 2 © 2006 by A-H. Esfahanian. All Rights Reserved.

Transitive Closure – optional Sunday, December 09, 2018 Transitive Closure – optional Lemma: Let R be a relation on S={v1,v2,…,vn}, and let Wk=[w[k]ij] be the 0-1 matrix | w[k]ij=1   a path from vi to vj with interior vertices in {v1, v2, …, vk}. Then i,j,kn w[k]ij = w[k-1]ij  (w[k-1]ikw[k-1]kj). © 2006 by A-H. Esfahanian. All Rights Reserved.

Algorithm 2 - Warshall’s Algorithm Sunday, December 09, 2018 Algorithm 2 - Warshall’s Algorithm Procedure for computing transitive closure: W = MR; For k=1 to n do the following: For i=1 to n do the following: For j=1 to n do the following: wij = wij  (wik  wkj); // That is, at step k: add row k to all other rows which have 1 as intersection with kth column. © 2006 by A-H. Esfahanian. All Rights Reserved.

Warshall’s Algorithm - Example Sunday, December 09, 2018 Warshall’s Algorithm - Example Find the matrix MR* of the transitive closure of R: MR = Solution: W0 = MR Add row 1 to row 3: W1 = Add row 2 to row 3: W2 = Add row 3 to row 1: MR* = W3 = © 2006 by A-H. Esfahanian. All Rights Reserved.

Conclusions: transitive closure Sunday, December 09, 2018 Conclusions: transitive closure Computing the transitive closure of a digraph is an important problem in many computer science applications: Evaluation of recursive database queries. Analysis of reachability (connectivity) of transition graphs in communication networks. Construction of parsing automata in compilers. © 2006 by A-H. Esfahanian. All Rights Reserved.

Equivalence relations These are reflexive, symmetric, and transitive. They partition the set of all elements into equivalence classes.

Examples Locations(points, cities) connected by bi directional roads. All cities connected to each other form an equivalence class – points on Mackinaw Is. People related by speaking the same FIRST language (assuming you can only have one). The real numbers related by absolute value: (5,5)(-5,5)(-π, π) … The set of all students partitioned according to major, assuming each student has ONE major.

Example: the integers mod m a R b = { (a, b) | a ≡ b (mod m) } If m=5 then we have 5 classes induced by R [0]R = { 0, 5, -5, 10, -10, 15, -15, …} [1]R = { 1, -1, 6, -6, 11, -11, …} [2]R = { 2, -2, 7, -7, 12, -12, …} [3]R = { 3, -3, 8, -8, 13, -13, …} [4]R = { 4, -4, 9, -9, 14, -14, …} Note that every integer belongs to one and only one of these classes – R partitions Z.

Example: pixel adjacency partitions a binary image into “blobs” or “objects” 15 subsets of pixels. Within each subset, pixels are connected by a path through neighbors. Pixels in each subset are not connected to pixels in any other subset. (Connecting paths are not allowed to go through background pixels.)

Functions induce equivalence classes f ( student ) = major (assume only one major); classes are f-1 (CS), f-1 (EE), f-1 (MTH), … g ( person ) = first_language (assume one) h ( x ) = 5 sin ( x ) = 0.707 weight ( person ) = 165 pounds c ( student ) = 1 iff student is in CSE260 Section 2 Fall 2009