CS0441 Discrete Structures Recitation 8

Xiang Xiao Transitive

Transitive Closure of R: The transitive closure of R is the smallest transitive that contains R. It is a subset of every containing R.

Finding the transitive closure of R:  Algorithm 1 (P. 603): “The transitive closure of a relation R equals the connectivity relation R*”

If R is a relation on A with n elements RRRRR* 2 3  n

MMMMM [2]  [3]    [n ] R* RRRR P607 Q26

Use Algorithm 1 to find the transitive closure of these relations on {a, b, c, d, e}.

{(a, c), (b, d), (c, a), (d, b), (e, d)}

0 0 1 0 0

0 0 0 1 0  M R  1 0 0 0 0  0 1 0 0 0

0 0 0 1 0

2 3 푛 Goal: 푀푅∗ = 푀푅 ∨ 푀푅 ∨ 푀푅 ∨⋅⋅⋅∨ 푀푅

Solution

0 0 1 0 0 0 0 0 1 0 푀푅 = 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0   0 0 1 0 0   1 0 0 0 0 0 0 0 1 0   0 0 0 1 0   0 1 0 0 0      [2] MMMRRR 1 0 0 0 0   1 0 0 0 0   0 0 1 0 0      0 1 0 0 0   0 1 0 0 0  0 0 0 1 0 0 0 0 1 0   0 0 0 1 0  0 1 0 0 0 1 0 0 0 0   0 0 1 0 0   0 0 1 0 0 0 1 0 0 0   0 0 0 1 0   0 0 0 1 0      [3] [2] MMMRRR 0 0 1 0 0   1 0 0 0 0   1 0 0 0 0      0 0 0 1 0   0 1 0 0 0  0 1 0 0 0 0 1 0 0 0   0 0 0 1 0  0 0 0 1 0 Solution

0 0 1 0 0   0 0 1 0 0   1 0 0 0 0 0 0 0 1 0   0 0 0 1 0   0 1 0 0 0      [4] [3] MMMRRR 1 0 0 0 0   1 0 0 0 0   0 0 1 0 0      0 1 0 0 0   0 1 0 0 0  0 0 0 1 0 0 0 0 1 0   0 0 0 1 0  0 1 0 0 0

1 0 0 0 0   0 0 1 0 0   0 0 1 0 0 0 1 0 0 0   0 0 0 1 0   0 0 0 1 0      [5] [4] MMMRRR 0 0 1 0 0   1 0 0 0 0   1 0 0 0 0      0 0 0 1 0   0 1 0 0 0  0 1 0 0 0 0 1 0 0 0   0 0 0 1 0  0 0 0 1 0 1 0 1 0 0 0 1 0 1 0  * [1] [2] [3] [4] [5] MMMMMMMRRRRRRR       1 0 1 0 0  0 1 0 1 0 0 1 0 1 0 Transitive Closure

Transitive Closure of R: The transitive closure of R is the smallest transitive relation that contains R. It is a subset of every transitive relation containing R.

Finding the transitive closure of R:  Algorithm 1 (P. 603): MMMMM [2]  [3]    [n ] R* RRRR  Warshall’s algorithm

[]k Wwk [] ij

W is the matrix of the transitive closure n

P607 Q28

Use Warshall’s algorithm to find the transitive closure of these relations on {a, b, c, d, e}.

{(a, c), (b, d), (c, a), (d, b), (e, d)}

Let v1 = a, v2 = b, v3 = c, v4 = d, v5 = e.

W0 is the matrix of the relation. Hence 0 0 1 0 0 0 0 0 1 0  WM0 R 1 0 0 0 0  0 1 0 0 0  0 0 0 1 0

Solution

0 0 1 0 0 0 0 0 1 0 푊0 = 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 푊1 = 1 0 1 0 0 wij = 1 if there is a path from vi to vj that 0 1 0 0 0 has only v = a as an interior vertex. 0 0 0 1 0 1 0 0 1 0 0 w = 1 if there is a path from v to v that has v = 0 0 0 1 0 ij i j 1 푊 = a and/or v = b as an interior vertex. 2 1 0 1 0 0 2 0 1 0 1 0 0 0 0 1 0 Solution

1 0 1 0 0 wij = 1 if there is a path from vi to vj that has v1 0 0 0 1 0 = a, v2 = b and/or v3 = c as an interior vertex. 푊3 = 1 0 1 0 0 0 1 0 1 0 0 0 0 1 0

1 0 1 0 0 wij = 1 if there is a path from vi to vj that has v1 = a, v = b, v = c and/or v = d as an interior 0 1 0 1 0 2 3 4 푊 = vertex. 4 1 0 1 0 0 0 1 0 1 0 0 1 0 1 0

1 0 1 0 0 wij = 1 if there is a path from vi to vj that has v1 0 1 0 1 0 = a, v2 = b, v3 = c, v4 = d and/or v5 = e as an 푊5 = 1 0 1 0 0 interior vertex. 0 1 0 1 0 0 1 0 1 0 Equivalence relations

Equivalence relations: The relation is reflexive, symmetric, and transitive.

Which of these relations are equivalence relations? a. {(a, b) | a and b have the same parents} Yes b. {(a, b) | a and b share a common parent} No, not transitive. c. {(a, b) | a and b have met} No, not transitive. P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such that ((a, b), (c, d)) ϵ R if and only if ad = bc. Show that R is an . Proof: 1. Show R is reflexive: For every two positive integers a and b, ab = ba; Therefore ((a, b), (a, b)) ϵ R. Hence R is reflexive. 2. Show R is symmetric: For every four positive integers a, b, c, d, if ((a, b), (c, d) ϵ R, then ad = bc. So cb = da. Therefore ((c, d), (a, b) ϵ R. Hence R is symmetric. 3. Show R is transitive: For every six positive integers a, b, c, d, e, f. if ((a, b), (c, d)) ϵ R and ((c, d), (e, f) ϵ R, then it follows that ad = bc and cf = ed. Therefore, acdf = bcde. remove cd from both sides, we have af = be. If af = be, then ((a, b), (e, f) ϵ R. Hence R is transitive. P616 Q40

• What is the equivalence class of (1, 2) with respect to the equivalence relation in the previous question?

Goal: find the set of all pairs that are related to (1,2)

Suppose a pair (a, b) is related to (1, 2), ((1, 2), (a, b)) ϵ R. Therefore, b = 2a. Hence, [(1, 2)] = {(1, 2), (2, 4), (3, 6), …… } = {(a, b) | b = 2a, a ϵ Z+}

P616 Q40

• Give an interpretation of the equivalence classes for the equivalence relation R in the previous question. [Hint: look at the ratio a/b corresponding to (a, b).]

Goal: for every element (a, b) ϵ R, a, b ϵ Z+, find all pairs that are related to it.

Suppose a pair (c, d) is related to (a, b), ((a, b), (c, d)) ϵ R. Therefore, ad = bc. It follows that a/b = c/d. Therefore, for every element (a, b) ϵ R, its equivalence class can be interpreted as a positive rational number a/b. Each equivalence class can be interpreted as an rational number.

What is the equivalence classes of the equivalence relation {(0, 0), (1, 1), (1, 2), (2, 1), (2, 2), (3, 3)}

[0] = {0} [1] = {1, 2} [2] = {1, 2} [3] = {3}