Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 103 Discrete Structures Lecture 19 Relations. Chapter 9.

Similar presentations


Presentation on theme: "CS 103 Discrete Structures Lecture 19 Relations. Chapter 9."— Presentation transcript:

1 CS 103 Discrete Structures Lecture 19 Relations

2 Chapter 9

3 Chapter Summary Relations and Their Properties

4 Section 9.1

5 Section Summary Relations and Functions Properties of Relations Reflexive Relations Symmetric and Antisymmetric Relations Transitive Relations Combining Relations

6 Binary Relations A relation is a subset of the Cartesian product Relations can be used to solve problems such as: Determining which pairs of cities are linked by airline flights in a network Finding a feasible order for the different phases of a complicated project Producing a useful way to store information in computer databases A binary relation R from a set A to a set B is a subset R ⊆ A × B. Therefore, R consists of ordered pairs where the 1 st element of each ordered pair comes from A and the 2 nd element comes from B

7 Binary Relations (a, b)  R means a is related to b by R a R b denotes (a, b)  R a R b denotes (a, b)  R Example 1: Let A be the set of students, B be the set of courses and R be the relation that consists of pairs (a, b), where a is a student enrolled in course b. Then, If Ahmad and Ali are enrolled in CS103, then (Ahmad, CS103)  R and (Ali, CS103)  R If Ahmad is also enrolled in CS111, then (Ahmad, CS111)  R If Ali is not enrolled in CS111, then (Ali, CS111)  R

8 Binary Relations Example 2: Let A be the set of cities, B be the set of regions. (a, b) belongs to R if city a is in region b Then (Al-Mahd, Al-Madinah), (Gada, Makkah), and (Al-Zolfy, Ryiadh) are in R Example 3 A = {0, 1, 2} B = {a, b} R = {(0, a), (0, b), (1, a), (2, b)} is a relation from A to B We also can represent the relation from the set A to the set B graphically or using a table

9 Binary Relations on a Set A binary relation on the set A is a relation from A to A. In other words, a relation on a set A is a subset of A  A Example 1: A = {a, b, c}. Then R = {(a, a),(a, b), (a, c)} is a relation on A Example 2: A = {1, 2, 3, 4}. Which ordered pairs are in the relation R = {(a, b) | a divides b}? R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}

10 How Many Relations on a Set? Because a relation on A is the same thing as a subset of A × A, we count the subsets of A × A As A × A has |A| 2 elements, and a set with m elements has 2 m subsets, therefore A × A has 2 |A| 2 subsets  there are 2 |A| 2 relations on a set A

11 Binary Relations on a Set: Example 3 Which of these relations on the set of integers contain each of the pairs (1, 1), (1, 2), (2, 1), (1, -1), and (2, 2)? R 1 = {(a, b) | a ≤ b} R 2 = {(a, b) | a > b} R 3 = {(a, b) | a = b or a = - b} R 4 = {(a, b) | a = b} R 5 = {(a, b) | a = b + 1} R 6 = {(a, b) | a + b ≤ 3} (1, 1)is inR 1, R 3, R 4, and R 6 (1, 2)is inR 1 and R 6 (2, 1) is inR 2, R 5, and R 6 (1, -1)is inR 2, R 3, and R 6 (2, 2)is inR 1, R 3, and R 4 Note that these relations are on an infinite set and each of these relations is an infinite set

12 Properties of Relations: Reflexive Properties are used to classify relations on a set A relation R on a set A is called reflexive iff ∀ x[x ∊ A ⟶ (x, x) ∊ R], i.e. (a, a)  R for every element a  A A= {1, 2, 3, 4} R 1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)} R 2 = {(1, 1), (1, 2), (2, 1)} R 3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)} R 4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)} R 5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)} R 6 = {(3, 4)}

13 Properties of Relations: Irreflexive Relation R on a set A is irreflexive if (a, a)  R for all a  A Some relations are neither reflexive nor irreflexive Example Let A = {1, 2} and R = {(1, 1)} It is not reflexive, because (2, 2)  R It is not irreflexive, because (1, 1)  R

14 Properties of Relations: Symmetric Relation R on a set A is symmetric iff (b, a)  R whenever (a, b)  R, for all a, b  A Relation R on a set A is antisymmetric iff (a, b)  R & (b, a)  R then a = b, for all a, b  A Relations can be symmetric & antisymmetric, simultaneously A = {1, 2, 3, 4} R 1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)} R 2 = {(1, 1), (1, 2), (2, 1)} R 3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)} R 4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)} R 5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)} R 6 = {(3, 4)}

15 Antisymmetric Property: Example Details R 1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)} Whenever 2 nd -last column shows Yes, last column does not show Yes.  R 5 is not Antisymmetric (a, b)(a, b)(b, a)(b, a) (b, a)  R 4 ? a=b?a=b? (1, 1) Yes (1, 2)(1, 2)(2, 1)YesNo (2, 1)(1, 2)YesNo (2, 2) Yes (3, 4)(4, 3)No- (4, 1)(1, 4)No- (4, 4) Yes

16 Antisymmetric Property: Example Details R 4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)} Whenever 2 nd -last column shows Yes, last column also shows Yes.  R 5 is Antisymmetric (a, b)(a, b)(b, a)(b, a) (b, a)  R 4 ? a=b?a=b? (2, 1)(1, 2)No- (3, 1)(3, 1)(1, 3)(1, 3) - (3, 2)(2, 3)No- (4, 1)(1, 4)No- (4, 2)(2, 4)No- (4, 3)(3, 4)No-

17 Antisymmetric Property: Example Details R 5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)} Whenever 2 nd -last column shows Yes, last column also shows Yes.  R 5 is Antisymmetric (a, b)(a, b)(b, a)(b, a) (b, a)  R 4 ? a=b?a=b? (1, 1) Yes (1, 2)(1, 2)(2, 1)(2, 1)No- (1, 3)(3, 1)No- (1, 4)(4, 1)No- (2, 2) Yes (2, 3)(3, 2)No- (2, 4)(4, 2)No- (3, 3) Yes (3, 4)(4, 3)No- (4, 4) Yes

18 Properties of Relations: Transitive Relation R on a set A is transitive if whenever (a, b)  R and (b, c)  R, then (a, c)  R, for all a, b, c  A A = {1, 2, 3, 4} R 1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)} R 2 = {(1, 1), (1, 2), (2, 1)} R 3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)} R 4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)} R 5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)} R 6 = {(3, 4)}

19 Transitive Property: Example Details R 1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)} Start with the first pair, (1,1). Here a=1, b=1. Are their pairs that have their 1 st elements as b? Yes Only one pair, (1, 2). Here b=1, c=2 Is (a, c) a member of R 1 ? Yes.  R 1 can be transitive. Now move to the next pair, (1, 2). Here a=1, b=2. Are their pairs that have their 1 st elements as b? Yes Two pairs, (2, 1), (2, 2). Here b=2, c=1 and c=2 Is (a, c) a member of R 1 ? Yes for both c=1 and c=2.  R 1 may be transitive. Now move to the next pair, (2, 1). Here a=2, b=1. Are their pairs that have their 1 st elements as b? Yes Two pairs, (1, 1), (1, 2). Here b=1, c=1 and c=2 Is (a, c) a member of R 1 ? Yes for both c=1 and c=2.  R 1 may be transitive. Now move to the next pair, (2, 2). Here a=2, b=2. Are their pairs that have their 1 st elements as b? Yes Two pairs, (2, 1), (2, 2). Here b=2, c=1 and c=2 Is (a, c) a member of R 1 ? Yes for both c=1 and c=2.  R 1 may be transitive. Now move to the next pair, (3, 4). Here a=3, b=4. Are their pairs that have their 1 st elements as b? Yes Two pairs, (4, 1), (4, 4). Here b=4, c=1 and c=4 Is (a, c) a member of R 1 ? No for c=1.  R 1 is not transitive. Finished! No need to do any further checking.

20 Transitive Property: Example Details R 4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)} There are no “No” answers in the last column. Therefore, the relation R 4 is transitive. (a, b)(a, b) Pairs with b as their 1 st element c (a, c)  R 4 ? (2, 1)--- (3, 1)(3, 1)--- (3, 2)(2, 1)1Yes (4, 1)--- (4, 2)(2, 1)1Yes (4, 3)(3, 1) (3, 2) 1212 Yes

21 Properties of Relations: Summary Reflexive  a  A,(a, a)  R Irreflexive  a  A,(a, a)  R Symmetric  a,b  A,(a, b)  R  (b, a)  R Antisymmetric  a,b  A,(a, b)  R  (b, a)  R  a = b Transitive  a,b,c  A,(a, b)  R  (b, c)  R  (a, c)  R

22 Combining Relations Relations are sets They can be combined in any way sets can be combined Example 1 Let A = {1, 2, 3}, B = {1, 2, 3, 4}, R 1 = {(1, 1), (2, 2), (3, 3)} R 2 = {(1, 1), (1, 2), (1, 3), (1, 4)}

23 Combining Relations: Example 2 R 1 = {(x, y) | x y}, where x,y  R R 1  R 2 = ? (x, y)  R 1  R 2 iff (x, y)  R 1 or (x, y)  R 2 (x, y)  R 1  R 2 iff x y x y implies that x  y  R 1  R 2 = {(x, y) | x  y} R 1  R 2 =  as (x, y) cannot belong to both R 1 & R 2 R 1 - R 2 = R 1 R 2 - R 1 = R 2 R 1  R 2 = R 1  R 2 - R 1  R 2 = {(x, y) | x  y} x > y x < y y -axis x-axis x = yx = y

24 R is a relation from set A to set B S is a relation from set B to set C The composite of R and S, S  R, is the relation consisting of ordered pairs (a, c), where a  A, c  C, and for which there exists an element b  B such that (a, b)  R and (b, c)  S Example R is the relation from A = {1, 2, 3} to B = {1, 2, 3, 4} R = {(1, 1), (1, 4), (2, 3), (3, 1), (3, 4)} S is the relation from B = {1, 2, 3, 4} to C = {0, 1, 2} S = {(1, 0), (2, 0), (3, 1), (3, 2), (4, 1)} S  R = {(1, 0), (1, 1), (2, 1), (2, 2), (3, 0), (3, 1)} b b c c a a a a b b c c Composite of Relations

25 Powers of a Relation For relation R on set A, powers R n, n = 1, 2, 3,..., are defined recursively by Example R = {(1, 1), (2, 1), (3, 2), (4, 3)} = R 1 R 2 = R  R = {(1, 1), (2, 1), (3, 1), (4, 2)} R 3 = R 2  R = {(1, 1), (2, 1), (3, 1), (4, 1)} R 4 = R 3  R = {(1, 1), (2, 1), (3, 1), (4, 1)} = R 3 R n = R 3 for n = 5, 6, 7,.... as well

26 Section 9.1: Exercises

27

28

29

30


Download ppt "CS 103 Discrete Structures Lecture 19 Relations. Chapter 9."

Similar presentations


Ads by Google