Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relations (2) Rosen 6 th ed., ch. 8. Closures of Properties Let R be a relation on a set A. R may or may not have some property P, such as reflexivity,

Similar presentations


Presentation on theme: "Relations (2) Rosen 6 th ed., ch. 8. Closures of Properties Let R be a relation on a set A. R may or may not have some property P, such as reflexivity,"— Presentation transcript:

1 Relations (2) Rosen 6 th ed., ch. 8

2 Closures of Properties Let R be a relation on a set A. R may or may not have some property P, such as reflexivity, symmetry, or transitivity. If there is a relation S with property P containing R such that S is a subset of every relation with property P containing R, then S is called the closure of R with respect to P. – For any property X, the “X closure” of a set A is defined as the “smallest” subset of A that has the given property.

3 Reflexive Closure Reflective closure of R is R  Δ, where Δ = {(a, a) | a  A} is the diagonal relation on A. EXAMPLE: What is the reflexive closure of the relation R = {(1, 1), (1, 2), (2, 1), (3, 2)} on the set A = {1, 2, 3}? Solution: R  Δ = {(1, 1), (1, 2), (2, 1), (3, 2)}  {(1, 1), (2, 2), (3, 3)} = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 2), (3, 3)}

4 Reflexive Closure Cont. EXAMPLE: What is the reflexive closure of the relation R = {(a, b) | a < b} on the set of integers? Solution: R  Δ = {(a, b) | a < b}  {(a, a) | a  Z} = {(a, b) | a ≤ b}.

5 Symmetric Closure R  R - is the symmetric closure of R, where R - = {(b, a) | (a, b)  R}. EXAMPLE: What is the symmetric closure of the relation R = {(a, b) | a > b} on the set of positive integers? Solution: R  R - = {(a, b) | a > b}  {(b, a) | a < b} = {(a, b) | a ≠ b}.

6 A case of transitivity closure Consider the relation R = {(1, 3), (1, 4), (2, 1), (3, 2)} on the set {1, 2, 3, 4}. This relation is not transitive since (1, 2), (2, 3), (2, 4), and (3, 1) is not in R. Adding (1, 2), (2, 3), (2, 4), and (3, 1), We get a relation {{(1, 3), (1, 2), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2)}. Is this relation transitive? => NO. The relation contains (3, 1) and (1, 4) but does not contain (3, 4) – Constructing the transitive closure of a relation is more complicate than constructing either the reflective or symmetric closure.

7 DEFINITION: A path from a to b in the directed graph G is a sequence of edges (x 0, x 1 ), (x 1, x 2 ), (x 2, x 3 ),…, (x n-1, x n ) in G, where n is a nonnegative integer, and x 0 = a and x n = b, that is, a sequence of edges where the terminal vertex of an edge is the same as the initial vertex in the next edge in the path. This path is denoted by x 0, x 1, x 2, …, x n-1, x n and has length n. We view the empty set of edges as a path from a to a. A path of length n ≥ 1 that begins and ends at the same vertex is called a circuit or cycle. Paths in Directed Graphs

8 Which of the following are paths in the directed graph shown below: a, b, e, d; a, e, c, d, b; b, a, c, b, a, a, b; d, c; c, b, a; e, b, a, b, a, b, e? What are the lengths of those that are paths? Which are circuit? – Paths: a, b, e, d(l=3); b, a, c, b, a, a, b(l=6); d, c(l=1); c, b, a(l=2); e, b, a, b, a, b, e(l=6) – Circuits: b, a, c, b, a, a, b; e, b, a, b, a, b, e Paths in Directed Graphs Cont. e a b d c

9 THEOREM: Let R be a relation on a set A. There is a path of length n, where n is a positive integer, from a to b if and only if (a, b)  R n. Paths in Directed Graphs Cont. 12341234 12341234 R 12341234 R 12341234 12341234 R2R2

10 DEFINITION: Let R be a relation on a set A. The connectivity relation R* consists of the pairs (a, b) such that there is a path of length at least one from a to b in R. Because R n consists of the pairs (a, b) such that there is a path of length n from a to b, it follows that R* is the union of all the sets R n. In other words, Transitive Closure

11 EXAMPLE: R 이 전 세계의 모든 사람들의 집합에 대한 관계이고 a 가 b 를 만난 적이 있으면 (a, b) 를 포함한다고 하자. R n (n 은 1 보다 큰 양의 정수 ) 은 무엇을 의미하는가 ? 또한 R* 는 무엇을 의미하는가 ? – 관계 R 2 는 (a, c)  R 이고 (c, b)  R 인 사람 c 가 있으면, 즉, a 가 c 를 만난 적이 있고 c 가 b 를 만난 적이 있는 사람 c 가 존재하면, (a, b) 를 포함한다. – 비슷하게, R n 은 a 가 x 1 을 만난 적이 있고, x 1 이 x 2 를 만 난 적이 있고, … x n-1 이 b 를 만난 적이 있는 사람들 x 1, x 2, …, x n-1 이 존재하는 (a, b) 들로 구성된다. – 관계 R* 는 어떤 순차 (sequence) 내의 각 사람이 순차 내의 다음 사람을 만난 적이 있는, a 에서 시작하여 b 로 끝나는 사람들의 순차가 존재하면 (a, b) 를 포함한 다. Transitive Closure Cont.

12 THEOREM: The transitive closure of a relation R equals the connectivity relation R*. THEOREM: Let M R be the zero-one matrix of the relation R on a set with n elements. Then the zero-one matrix of the transitive closure R* is Transitive Closure Cont.

13 EXAMPLE: Find the zero-one matrix of the transitive closure of the relation R where Example of Transitive Closure.

14 Because ⊙ = and ⊙ = Example Cont.

15 Simple Transitive Closure Alg. A procedure to compute R * with 0-1 matrices. procedure transClosure(M R : n x n 0-1 matrix) A := B := M R ; for i := 2 to n begin A := A ⊙ M R ; B := B  A {join} end return B{Alg. takes Θ(n 4 ) time} {note A represents R i }

16 Warshall’s Algorithm 앞서 설명한 R* 알고리즘의 시간 복잡도는 O(n 4 ) 이다. 따라 서 좀 더 빠른 시간 안에 R* 를 구할 수 있는 알고리즘이 필 요했으며, 1960 년에 Warshall 이 새로운 알고리즘을 발표한 다. 내부 정점 (internal vertex) – 만약 a, x 1, x 2, …, x m-1, b 가 경로 (path) 이면, 내부 정점은 x 1, x 2, …, x m-1 이다. 즉, 맨 앞과 맨 뒤가 아닌 경로 상의 임의 의 위치에 놓인 정점이 내부 정점이다.

17 Warshall’s Algorithm Warshall 의 알고리즘은 일련의 0-1 행렬을 구하는 것에 기 초한다. 이들 행렬은 W 0, W 1, … W n 이며 W 0 은 M R ( 주어진 관 계 R 의 0-1 행렬 ) 이고, 에서 는 모든 내부 정 점이 집합 {v 1, v 2, … v k } ( 앞 부분 k 개의 정점 ) 의 원소인 v i 에서 v j 로의 경로가 존재하면 1 이고, 그렇지 않으면 0 이다. 이렇게 해서 W n (n 은 관계 R 이 정의된 집합의 원소의 수 ) 을 구하면 W n = M R* 이다.

18 Warshall’s Algorithm EXAMPLE: Let R be the relation with directed graph shown below. Let a, b, c, d be a listing of the elements of the set. Find the matrices W 0, W 1, W 2, W 3, and W 4. The matrix W 4 is the transitive closure of R. Solution: v 1 = a, v 2 = b, v 3 = c, v 4 = d 라 하자. W 0 는 주 어진 관계의 행렬이므로, W 0 =. c a b d

19 Warshall’s Algorithm W 1 은 내부 정점으로 v 1 = a 만을 포함하는 v i 에서 v j 로의 경 로가 있으면 (i, j) 위치를 1 로 한다. 길이 1 인 이전의 경로들 은 내부 정점이 없으므로 여기서도 모두 1 이다. 이제, b 에서 d 로 가는 경로 b, a, d 가 허용되므로, W 1 =. ( 이전 단계에서 (i, a) 위치와 (a, j) 가 모두 1 이었던 (i, j) 들의 위치를 1 로 한다.) c a b d

20 Warshall’s Algorithm W 2 는 내부 정점으로 v 1 = a 와 v 2 = b 만을 포함하는 v i 에서 v j 로의 경로가 있으면 (i, j) 위치를 1 로 한다. b 로 향하는 간선 (edge) 이 없으므로, 변화가 없다. W 2 =. c a b d

21 Warshall’s Algorithm W 3 은 내부 정점으로 v 1 = a, v 2 = b 와 v 3 = c 만을 포함하는 v i 에서 v j 로의 경로가 있으면 (i, j) 위치를 1 로 한다. d 에서 a 로 가는 경로 d, c, a 와 d 에서 d 로 가는 경로 d, c, d 가 허용되므로, W 3 =. ( 이전 단계에서 (i, c) 위치와 (c, j) 가 모두 1 이었던 (i, j) 들의 위치를 1 로 한다.) c a b d

22 Warshall’s Algorithm W 4 는 d 까지 포함하여 모든 정점을 내부 정점으로 허용한 다. 따라서, v i 에서 v j 로의 경로가 있는 모든 (i, j) 위치를 1 로 한다 W 4 =. c a b d

23 Warshall’s Algorithm Uses only Θ(n 3 ) operations! Procedure Warshall(M R : rank-n 0-1 matrix) W := M R for k := 1 to n for i := 1 to n for j := 1 to n w ij := w ij  (w ik  w kj ) return W {this represents R * } w ij = 1 means there is a path from i to j going only through nodes ≤k

24 Equivalence Relations An equivalence relation (e.r.) on a set A is simply any binary relation on A that is reflexive, symmetric, and transitive. – E.g., = itself is an equivalence relation.

25 Equivalence Relation Examples “Strings a and b are the same length.” “Integers a and b have the same absolute value.” “Real numbers a and b have the same fractional part (i.e., a − b  Z).” “Integers a and b have the same residue modulo m.” (for a given m>1)

26 Equivalence Classes Let R be any equiv. rel. on a set A. The equivalence class of a, [a] R :≡ { b | aRb } (optional subscript R) – It is the set of all elements of A that are “equivalent” to a according to the eq.rel. R. – Each such b (including a itself) is called a representative of [a] R.

27 Equivalence Class Examples “Strings a and b are the same length.” – [a] = the set of all strings of the same length as a. “Integers a and b have the same absolute value.” – [a] = the set {a, −a} “Real numbers a and b have the same fractional part (i.e., a − b  Z).” – [a] = the set {…, a−2, a−1, a, a+1, a+2, …} “Integers a and b have the same residue modulo m.” (for a given m>1) – [a] = the set {…, a−2m, a−m, a, a+m, a+2m, …}

28 Partitions A partition of a set A is the set of all the equivalence classes {A 1, A 2, … } for some e.r. on A. The A i ’s are all disjoint and their union = A. They “partition” the set into pieces. Within each piece, all members of the set are equivalent to each other.

29 An example of Partition EXAMPLE: What are the partition of the integers arising from congruence modulo 4? Solution: [0] 4 = {…, -8, -4, 0, 4, 8, …} [1] 4 = {…, -7, -3, 1, 5, 9, …} [2] 4 = {…, -6, -2, 2, 6, 10, …} [3] 4 = {…, -5, -1, 3, 7, 11, …} These classes are disjoint, and every integer is in exactly one of them. They form a partition.


Download ppt "Relations (2) Rosen 6 th ed., ch. 8. Closures of Properties Let R be a relation on a set A. R may or may not have some property P, such as reflexivity,"

Similar presentations


Ads by Google