Epp, section 10.? CS 202 Aaron Bloomfield

Slides:



Advertisements
Similar presentations
Mathematical Preliminaries
Advertisements

Advanced Piloting Cruise Plot.
Generating Random Spanning Trees Sourav Chatterji Sumit Gulwani EECS Department University of California, Berkeley.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
Analysis of Algorithms
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
and 6.855J Cycle Canceling Algorithm. 2 A minimum cost flow problem , $4 20, $1 20, $2 25, $2 25, $5 20, $6 30, $
1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine.
Introduction to Algorithms 6.046J/18.401J/SMA5503
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 5 second questions
ZMQS ZMQS
Reductions Complexity ©D.Moshkovitz.
Graph Algorithms - 3 Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 13Feb 12, 2014Carnegie Mellon University.
Copyright © Cengage Learning. All rights reserved.
Randomized Algorithms Randomized Algorithms CS648 1.
ABC Technology Project
Comp 122, Spring 2004 Graph Algorithms – 2. graphs Lin / Devi Comp 122, Fall 2004 Identification of Edges Edge type for edge (u, v) can be identified.
VOORBLAD.
Great Theoretical Ideas in Computer Science
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Great Theoretical Ideas in Computer Science for Some.
Squares and Square Root WALK. Solve each problem REVIEW:
CS1022 Computer Programming & Principles
Graphs, representation, isomorphism, connectivity
© 2012 National Heart Foundation of Australia. Slide 2.
CS1022 Computer Programming & Principles Lecture 7.1 Graphs (1)
Discrete Mathematics 3. MATRICES, RELATIONS, AND FUNCTIONS Lecture 5 Dr.-Ing. Erwin Sitompul
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Complexity ©D.Moshkovits 1 Where Can We Draw The Line? On the Hardness of Satisfiability Problems.
Week 1.
Graphs - II Algorithms G. Miller V. Adamchik CS Spring 2014 Carnegie Mellon University.
1 Let’s Recapitulate. 2 Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Rizwan Rehman Centre for Computer Studies Dibrugarh University
CS203 Lecture 15.
PSSA Preparation.
 Theorem 5.9: Let G be a simple graph with n vertices, where n>2. G has a Hamilton circuit if for any two vertices u and v of G that are not adjacent,
Equivalence Relations
The Pumping Lemma for CFL’s
Advanced Topics in Algorithms and Data Structures
all-pairs shortest paths in undirected graphs
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.
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 Representing Relations Epp section ??? CS 202 Aaron Bloomfield.
Applied Discrete Mathematics Week 10: Equivalence Relations
1 Closures of Relations: Transitive Closure and Partitions Sections 8.4 and 8.5.
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.
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.
1 Closures of Relations Based on Aaron Bloomfield Modified by Longin Jan Latecki Rosen, Section 8.4.
Aaron Bloomfield CS 202 Rosen, section 7.4
Computing Connected Components on Parallel Computers
Closures of Relations Epp, section 10.1,10.2 CS 202.
Representing Relations Using Matrices
Presentation transcript:

Epp, section 10.? CS 202 Aaron Bloomfield Closures of Relations Epp, section 10.? CS 202 Aaron Bloomfield

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

Reflexive closure 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 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

Reflexive closure example 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 1 3 2 We add edges: (0,0), (3,3)

Symmetric closure 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 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) | … }

Symmetric closure example 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 1 3 2 We add edges: (0,2), (0,3) (1,0), (2,1)

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) Start (a) End (b) Start (a) End (b)

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

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

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

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! (1,2) & (2,3) (1,3) (2,3) & (3,4) (2,4) R = { (1,2), (2,3), (3,4) } 1 2 3 4 1 2 3 4

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 1 2 3 4

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)  R6

Connectivity relation R contains edges between all the nodes reachable via 1 edge R◦R = R2 contains edges between nodes that are reachable via 2 edges in R R2◦R = R3 contains edges between nodes that are reachable via 3 edges in R Rn = 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

End of lecture on 6 April 2007 In both classes

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 (x0, x1), (x1, x2), …, (xm-1, xm) That’s nodes x0, x1, x2, …, xm-1, xm 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

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

Finding the transitive closure Let MR 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

Sample questions Find the zero-one matrix of the transitive closure of the relation R given by: 1 2 3 1 2 3 

Sample questions  1 2 3

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 Join that with from above

Transitive closure algorithm procedure transitive_closure (MR: zero-one nn matrix) A := MR B := A for i := 2 to n begin A := A MR B := B  A end { B is the zero-one matrix for R* } 

More transitive closure algorithms More efficient algorithms exist, such as Warshall’s algorithm We won’t be studying it in this class