Professional Documents
Culture Documents
BITS Pilani
§4.5: Operations on relations
1
Operations on n-ary relations
2
Operations on n-ary relations
2
Operations on n-ary relations
2
Operations on n-ary relations
2
Operations on n-ary relations (Contd.)
Definition
Let R ✓ (A1 ⇥ · · · ⇥ An ) be an n-ary relation and let s1 , . . . , sk be a
subsequence of the component positions 1, . . . , n of R. The projection
of R with respect to s1 , . . . , sk is the k-ary relation
3
Operations on n-ary relations (Contd.)
Definition
Let R ✓ (A1 ⇥ · · · ⇥ An ) be an n-ary relation and let s1 , . . . , sk be a
subsequence of the component positions 1, . . . , n of R. The projection
of R with respect to s1 , . . . , sk is the k-ary relation
3
Operations on n-ary relations (Contd.)
Definition
Let R1 ✓ (A1 ⇥ · · · ⇥ An ) and R2 ✓ B1 ⇥ · · · ⇥ Bm be relations and
suppose Ai = Bj for some i, j. The join of R1 and R2 with respect to
component i of R1 and component j of R2 is the relation
4
Operations on n-ary relations (Contd.)
Definition
Let R1 ✓ (A1 ⇥ · · · ⇥ An ) and R2 ✓ B1 ⇥ · · · ⇥ Bm be relations and
suppose Ai = Bj for some i, j. The join of R1 and R2 with respect to
component i of R1 and component j of R2 is the relation
4
Operations on binary relations
Definition
Suppose R ✓ A ⇥ B. The inverse of R is the relation
1
R = {(y , x) : (x, y ) 2 R}.
5
Operations on binary relations
Definition
Suppose R ✓ A ⇥ B. The inverse of R is the relation
1
R = {(y , x) : (x, y ) 2 R}.
Note that the inverse of a relation is the relation itself if and only if the
relation is symmetric.
5
Operations on binary relations
Definition
Suppose R ✓ A ⇥ B. The inverse of R is the relation
1
R = {(y , x) : (x, y ) 2 R}.
Note that the inverse of a relation is the relation itself if and only if the
relation is symmetric.
Example. The inverse of the relation on Z is the relation
5
Example
6
Example
Then
1
R = {(y , x), (z, y ), (y , z), (x, z)}.
6
Example
Then
1
R = {(y , x), (z, y ), (y , z), (x, z)}.
The digraph of the inverse relation of a relation has exactly the edges of
the digraph of the original relation, but the directions of the edges are
reversed.
6
Example
Then
1
R = {(y , x), (z, y ), (y , z), (x, z)}.
The digraph of the inverse relation of a relation has exactly the edges of
the digraph of the original relation, but the directions of the edges are
reversed.
6
Exercise 1 (b), (d)
R = {(a, b), (b, c), (b, d), (d, a), (c, c)}.
1
Draw a digraph for R and a digraph for R \ R .
7
Exercise 1 (b), (d)
R = {(a, b), (b, c), (b, d), (d, a), (c, c)}.
1
Draw a digraph for R and a digraph for R \ R .
7
Operations on binary relations (contd.)
Definition
Suppose R1 ✓ A ⇥ B and R2 ✓ B ⇥ C . The composition of R1 and R2
is the relation
R1 · R2 = {(x, z) : (x, y ) 2 R1 , (y , z) 2 R2 }.
8
Operations on binary relations (contd.)
Definition
Suppose R1 ✓ A ⇥ B and R2 ✓ B ⇥ C . The composition of R1 and R2
is the relation
R1 · R2 = {(x, z) : (x, y ) 2 R1 , (y , z) 2 R2 }.
Then
R1 · R2 = {(a, a), (a, c), (a, d), (c, c), (c, d)}.
8
Exercise 14 (a), (b)
Suppose that R1 , R2 are binary relations on a set A. Prove or disprove:
9
Exercise 14 (a), (b)
Suppose that R1 , R2 are binary relations on a set A. Prove or disprove:
Answer. (a) is true; (b) is false (for example, if A = {a, b}, then
R1 = {(a, b)}, R2 = {(b, a)} are irreflexive relations on A, but
R1 · R2 = {(a, a)} is reflexive.)
9
• Composition of relations is associative: if R, S, T are relations, then
(R · S) · T = R · (S · T )
• Notation: R 1 = R and for k 1, R k+1 = R k · R. Note that
R k+n = R k · R n
10
Closure property
Definition
If P is a property such that P can be made true for any set by adding
certain elements to the set, we call P a closure property, and define the
P-closure of the set to be the smallest set that contains it and satisfies
property P.
11
Closure property
Definition
If P is a property such that P can be made true for any set by adding
certain elements to the set, we call P a closure property, and define the
P-closure of the set to be the smallest set that contains it and satisfies
property P.
11
Exercise 8
12
Exercise 8
Answer.
12
Transitive closure
Definition
Suppose R ✓ A ⇥ A. The transitive closure of a binary relation is the
smallest relation that contains it and is transitive. We will see that the
transitive closure of R is
R+ = R [ R2 [ R3 [ · · ·
R ⇤ = R + [ {(a, a) : a 2 A}.
13
Proof
Theorem
R + is the smallest relation that contains R that is transitive.
14
Proof
Theorem
R + is the smallest relation that contains R that is transitive.
14
Proof
Theorem
R + is the smallest relation that contains R that is transitive.
14
Proof
Theorem
R + is the smallest relation that contains R that is transitive.
14
Examples
15
Examples
15
Examples
15
Exercise 6
16
Exercise 6 (Soln.)
17
§4.6: Paths and closures
18
Path
Definition
A directed path in a digraph A = (V , E ) is a sequence of zero or more
edges e1 , . . . , en in E for which there is sequence of vertices v0 , . . . , vn
such that
ei = (vi 1 , vi ), i = 1, . . . , n.
We say that this is a path from v0 to vn ; v0 , vn are its endpoints, and
its length is n.
19
Path
Definition
A directed path in a digraph A = (V , E ) is a sequence of zero or more
edges e1 , . . . , en in E for which there is sequence of vertices v0 , . . . , vn
such that
ei = (vi 1 , vi ), i = 1, . . . , n.
We say that this is a path from v0 to vn ; v0 , vn are its endpoints, and
its length is n.
A nondirected path in G is a sequence of zero or more edges e1 , . . . , en
in E for which there is sequence of vertices v0 , . . . , vn such that
ei = (vi 1 , vi ) or , ei = (vi , vi 1 ), i = 1, . . . , n.
19
Path
Definition
A directed path in a digraph A = (V , E ) is a sequence of zero or more
edges e1 , . . . , en in E for which there is sequence of vertices v0 , . . . , vn
such that
ei = (vi 1 , vi ), i = 1, . . . , n.
We say that this is a path from v0 to vn ; v0 , vn are its endpoints, and
its length is n.
A nondirected path in G is a sequence of zero or more edges e1 , . . . , en
in E for which there is sequence of vertices v0 , . . . , vn such that
ei = (vi 1 , vi ) or , ei = (vi , vi 1 ), i = 1, . . . , n.
A path is said to be simple if all edges and vertices on the path are
distinct, except that v0 and vn may be equal.
19
Path
Definition
A directed path in a digraph A = (V , E ) is a sequence of zero or more
edges e1 , . . . , en in E for which there is sequence of vertices v0 , . . . , vn
such that
ei = (vi 1 , vi ), i = 1, . . . , n.
We say that this is a path from v0 to vn ; v0 , vn are its endpoints, and
its length is n.
A nondirected path in G is a sequence of zero or more edges e1 , . . . , en
in E for which there is sequence of vertices v0 , . . . , vn such that
ei = (vi 1 , vi ) or , ei = (vi , vi 1 ), i = 1, . . . , n.
A path is said to be simple if all edges and vertices on the path are
distinct, except that v0 and vn may be equal.
A path of length 1 with no repeated edges and whose endpoints are
equal is called a circuit. A simple circuit is called a cycle.
19
Path
Definition
A directed path in a digraph A = (V , E ) is a sequence of zero or more
edges e1 , . . . , en in E for which there is sequence of vertices v0 , . . . , vn
such that
ei = (vi 1 , vi ), i = 1, . . . , n.
We say that this is a path from v0 to vn ; v0 , vn are its endpoints, and
its length is n.
A nondirected path in G is a sequence of zero or more edges e1 , . . . , en
in E for which there is sequence of vertices v0 , . . . , vn such that
ei = (vi 1 , vi ) or , ei = (vi , vi 1 ), i = 1, . . . , n.
A path is said to be simple if all edges and vertices on the path are
distinct, except that v0 and vn may be equal.
A path of length 1 with no repeated edges and whose endpoints are
equal is called a circuit. A simple circuit is called a cycle.
A path of non-zero length is called a nontrivial path. 19
Definition
A path e1 , . . . , en is said to traverse a vertex x if one (or more) of the
ei ’s is to or from x and x is not one of the endpoints.
20
Definition
A path e1 , . . . , en is said to traverse a vertex x if one (or more) of the
ei ’s is to or from x and x is not one of the endpoints.
20
Exercise 1
21
22
23
Exercise 6
What is the longest length possible for a simple directed path in a
digraph with n vertices? How about the longest cycle?
24
Exercise 6
What is the longest length possible for a simple directed path in a
digraph with n vertices? How about the longest cycle?
Answer. In a simple path, only the starting vertex may repeat. Therefore
the length of a simple path (and hence a cycle) is at most n.
24
Paths and composition
Theorem
If A = (V , E ) is a digraph, then for n 1, (x, y ) 2 E n = E · E . . . · E if
and only if there is a directed path of length n from x to y in A.
25
Paths and composition
Theorem
If A = (V , E ) is a digraph, then for n 1, (x, y ) 2 E n = E · E . . . · E if
and only if there is a directed path of length n from x to y in A.
25
Paths and composition
Theorem
If A = (V , E ) is a digraph, then for n 1, (x, y ) 2 E n = E · E . . . · E if
and only if there is a directed path of length n from x to y in A.
(v0 , v1 ), . . . , (vn 1 , vn ), v0 = x, vn = y .
25
Proof (contd.)
(v0 , v1 ), . . . , (vn 2 , vn 1 )
26
Proof (contd.)
(v0 , v1 ), . . . , (vn 2 , vn 1 )
26
Proof (contd.)
(v0 , v1 ), . . . , (vn 2 , vn 1 )
26
Remark. If R is a relation on a set of n vertices, then any path of length
greater than n between two vertices must have a repeated vertex and
hence must include a circuit. Such a path can therefore be shortened to a
path of length at most n. Hence R + = R [ R 2 [ . . . [ R n .
27
Remark. If R is a relation on a set of n vertices, then any path of length
greater than n between two vertices must have a repeated vertex and
hence must include a circuit. Such a path can therefore be shortened to a
path of length at most n. Hence R + = R [ R 2 [ . . . [ R n .
Question
Let A = {a, b, c, d, e} and
R = {(a, a), (a, b), (b, c), (c, d), (c, e), (d, e)}. Find the transitive
closure of R.
27
Remark. If R is a relation on a set of n vertices, then any path of length
greater than n between two vertices must have a repeated vertex and
hence must include a circuit. Such a path can therefore be shortened to a
path of length at most n. Hence R + = R [ R 2 [ . . . [ R n .
Question
Let A = {a, b, c, d, e} and
R = {(a, a), (a, b), (b, c), (c, d), (c, e), (d, e)}. Find the transitive
closure of R.
We have
R 2 = {(a, a), (a, b), (a, c), (b, e), (b, d), (c, e)}
R 3 = {(a, a), (a, b), (a, c), (a, d), (a, e), (b, e)}
R 4 = {(a, a), (a, b), (a, c), (a, d), (a, e)} = R 5 .
Hence R + = R [ R 2 [ . . . [ R 5 =
{(a, a), (a, b), (a, c), (a, d), (a, e), (b, c), (b, d), (b, e), (c, d), (c, e), (d, e)}.
27
Connectivity
Definition
Two vertices x, y in a digraph are said to be
28
Connectivity
Definition
Two vertices x, y in a digraph are said to be
Definition
A graph is (weakly, unilaterally, strongly) connected if every pair of
vertices in the graph is (weakly, unilaterally, strongly) connected.
28
Connectivity
Definition
Two vertices x, y in a digraph are said to be
Definition
A graph is (weakly, unilaterally, strongly) connected if every pair of
vertices in the graph is (weakly, unilaterally, strongly) connected.
Definition
A subgraph A1 of a graph A is a (weakly, unilaterally, strongly)
connected component if it is (weakly, unilaterally, strongly) connected
and there is no (weakly, unilaterally, strongly) connected subgraph of A
that properly contains A1 .
28
Example
29
Example
29
Example
29
Example
29
Exercise 3
30
Exercise 3
30
Exercise 3
30