cs0441 discrete structures recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/recitation-8.pdf ·...

14
CS0441 Discrete Structures Recitation 8 Xiang Xiao

Upload: others

Post on 18-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

CS0441 Discrete Structures Recitation 8

Xiang Xiao

Page 2: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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): “The transitive closure of a relation R equals the connectivity relation R*”

* 2 3

If R is a relation on set A with n elements

nR R R R R

*

[2] [3] [ ]n

R R R RRM M M M M

Page 3: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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)}

Goal: 𝑀𝑅∗ = 𝑀𝑅 ∨ 𝑀𝑅2∨ 𝑀𝑅

3∨⋅⋅⋅∨ 𝑀𝑅

𝑛

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

RM

Page 4: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

Solution

𝑀𝑅 =

0 0 1 0 00 0 0 1 01 0 0 0 00 1 0 0 00 0 0 1 0

[2]

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

1 0 0 0 0 1 0 0 0 0

0 1 0 0 0 0 1 0 0 0

0 0 0 1 0 0 0 0 1 0

R R RM M M

0 0

0 0 1 0 0

0 0 0 1 0

0 1 0 0 0

[3] [2]

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

0 0 1 0 0 1 0 0 0 0

0 0 0 1 0 0 1 0 0 0

0 1 0 0 0 0 0 0 1 0

R R RM M M

1 0

1 0 0 0 0

0 1 0 0 0

0 0 0 1 0

Page 5: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

Solution

[4] [3]

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

1 0 0 0 0 1 0 0 0 0

0 1 0 0 0 0 1 0 0 0

0 0 0 1 0 0 0 0 1 0

R R RM M M

0 0

0 0 1 0 0

0 0 0 1 0

0 1 0 0 0

[5] [4]

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

0 0 1 0 0 1 0 0 0 0

0 0 0 1 0 0 1 0 0 0

0 1 0 0 0 0 0 0 1 0

R R RM M M

1 0

1 0 0 0 0

0 1 0 0 0

0 0 0 1 0

* [1] [2] [3] [4] [5]

1 0 1 0 0

0 1 0 1 0

1 0 1 0 0

0 1 0 1 0

0 1 0 1 0

R R R R R R RM M M M M M M

Page 6: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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):

Warshall’s algorithm

*

[2] [3] [ ]n

R R R RRM M M M M

[ ][ ]

is the matrix of the transitive closure

k

k ij

n

W w

W

Page 7: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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 0 1 0 0

0 0 0 1 0

1 0 0 0 0

0 1 0 0 0

0 0 0 1 0

RW M

Page 8: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

Solution

𝑊0 =

0 0 1 0 00 0 0 1 01 0 0 0 00 1 0 0 00 0 0 1 0

𝑊1 =

0 0 1 0 00 0 0 1 01 0 1 0 00 1 0 0 00 0 0 1 0

𝑊2 =

0 0 1 0 00 0 0 1 01 0 1 0 00 1 0 1 00 0 0 1 0

wij = 1 if there is a path from vi to vj that has only v1 = a as an interior vertex.

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

Page 9: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

Solution

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

1 0 1 0 00 0 0 1 01 0 1 0 00 1 0 1 00 0 0 1 0

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

𝑊4 =

1 0 1 0 00 1 0 1 01 0 1 0 00 1 0 1 00 1 0 1 0

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

𝑊5 =

1 0 1 0 00 1 0 1 01 0 1 0 00 1 0 1 00 1 0 1 0

Page 10: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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}

b. {(a, b) | a and b share a common parent}

c. {(a, b) | a and b have met}

Yes

No, not transitive.

No, not transitive.

Page 11: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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 equivalence relation.

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.

Page 12: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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+}

Page 13: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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.

Page 14: CS0441 Discrete Structures Recitation 7people.cs.pitt.edu/~xiangxiao/cs0441/Recitation-8.pdf · P615 Q16 Let R be the relation on the set of ordered pairs of positive integers such

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}