Escolar Documentos
Profissional Documentos
Cultura Documentos
Science
Adam J. Lee
adamlee@cs.pitt.edu
6111 Sennott Square
Lecture #27: Closures of Relations
December 3, 2013
Announcements
No more homework!
Thursday: Course wrap-up and review
l Same format as midterm review
Today
Types of closures
l Symmetric closure
l Reflexive closure
l Transitive closure
Transitive closures
l Repeated relational composition
l Warshalls algorithm
Examples
Motivating Example
A computer network has data centers in Boston, Chicago, Denver,
Detroit, New York, and San Diego. There are direct, one-way
telephone lines from Boston to Chicago, Boston to Detroit,
Chicago to Detroit, Detroit to Denver, and New York to San Diego.
Let R be the relation containing (a, b) if there is a line from the
data center in a to the data center in b.
Note: The relation R is not transitive! How can we tell who can
communicate with whom?
D2
B
C
D1
S
What is a closure?
Definition: Let R be some relation on a set A. R may or may not
have some property P (e.g., reflexivity, symmetry, or
transitivity). If there is a relation S R with the property P such
that S is a subset of every relation containing R with the property
P, then S is called the closure of R with respect to P.
Informally: The closure of a relation R with respect to a property
P is the smallest extension to R that does have the property P.
but R A is reflexive
B
C
D1
S
Note:
l R-1 = {(C, B), (D2, B), (D2, C), (D1, D2), (S, N)}
l The symmetric closure is R R-1
l This is a can talk graph J
No!
Yes!
a
Yes!
Example:
l R = {(1,3), (2,3), (3,4)}
l R2 = {(1,3), (2,3), (3,4), (1,4), (2, 4)}
1
1
3
3
2
R =
Rn
(Why?)
n=1
To show containment:
l
l
l
l
R =
i=1
Ri =
Ri
i=1
1 0 1
MR = 0 1 0
1 1 0
[2]
MR
[1]
MR = MR
1
= 0
1
[2]
MR
1
1
1
[3]
MR
1
0
1
1
= 0
1
[3]
MR
1
1
1
1
0
1
1
= 0
1
1
1
1
1
0
1
Main idea:
l
l
l
l
l
Compute
Compute
Compute
Compute
0 0
1 0
W 0 = MR =
1 0
0 0
0
1
W1 =
1
0
0
1
0
1
1
0
1
0
0 1 1
0 0 1 W allows paths through {1, 2}
2
0 1 0
Nothing new
0
1
W3 =
1
1
0
0
0
0
1
1
W4 =
1
1
0
0
0
0
0
1
0
1
1
1
1
1
1
1, 4, 3, 1 is now valid
1
3, 4, 3 is now valid
1
0
1
W 0 = MR =
1
0
0
0
0
0
0
1
0
1
1
0
1
0
0
1
W1 =
1
0
0
0
0
0
0
1
0
1
1
1
1
0
0
1
W3 =
1
1
0
0
0
0
0
1
0
1
1
1
1
1
1
1
W4 =
1
1
0
0
0
0
1
1
1
1
1
1
1
1
Warshalls algorithm
Procedure: warshall(MR : n x n zero-one matrix)
W := MR
for k := 1 to n
for i := 1 to n
for j := 1 to n
wij := wij (wik wkj)
end
Note: After this procedure, W = [wij] contains the zero-one matrix
for the relation R*
n times
2 binary operations
Group work!
Let A = {0, 1, 2, 3} and let R = {(0,1), (1,1), (1,2), (2,0), (2,2), (3,0)}
Problem 1: Find the reflexive closure of R
Problem 2: Find the symmetric closure of R
Let A = {1, 2, 3, 4} and let R = {(2,1), (2,3), (3,1), (3,4), (4,1), (4,3)}
Problem 3: Draw R as a graph
Problem 4: Use our first algorithm to find the transitive closure of R
Problem 5: Use Warshalls algorithm to find the transitive closure of R
Final Thoughts
Closures of relations have many uses in computer science
Computing reflexive and symmetric closures is easy!
Transitive closures take more work to do right
l Intuitive algorithm: 2n3(n-1) bit operations
l Warshalls algorithm: 2n3 bit operations