Professional Documents
Culture Documents
26 Closures of Relations
26 Closures of Relations
Aaron Bloomfield
CS 202
Rosen, section 7.4
1
Relational closures
Three types we will study
Reflexive
Easy
Symmetric
Easy
Transitive
Hard
2
Reflexive closure
Consider a relation R:
From our MapQuest example in the last slide set
Note that it is not reflexive
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
We add edges:
(0,0), (3,3)
3
2
5
Symmetric closure
Consider a relation R:
From our MapQuest example in the last slide set
Note that it is not symmetric
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) | }
We add edges:
(0,2), (0,3)
(1,0), (2,1)
3
2
8
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
10
Shortest paths
What is really needed in most applications
is finding the shortest path between two
vertices
11
Fan-supplied demotivators!
12
Transitive closure
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
1
2
3
15
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
4
1
2
3
16
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
Or, (a,g) R6
17
Connectivity relation
19
20
Nodes reachable
with two applications
of the relation
Nodes reachable
with n applications
of the relation
21
M [R2 ]
M R* M R M [R2] M [R3]
M [R2] M R
1 0 1
M R 0 1 0
1 1 0
1 0 1 1 1 1
0 1 0 0 1 0
1 1 0 1 1 1
22
1 1 1
M R 0 1 0
1 1 1
1 0 1 1 1 1
0 1 0 0 1 0
1 1 0 1 1 1
M R*
1 0 1 1 1 1 1 1 1 1 1 1
0 1 0 0 1 0 0 1 0 0 1 0
1 1 0 1 1 1 1 1 1 1 1 1
23
M
Compute R
R MR
[ 2]
M
M
Join that with R
R from above
24
25
26
Motivational posters
27
Quick survey
a)
b)
c)
d)
28
Quick survey
a)
b)
c)
d)
29
Quick survey
a)
b)
c)
d)
30