cs 103 discrete structures lecture 19 relations. chapter 9
TRANSCRIPT
CS 103 Discrete Structures
Lecture 19
Relations
RelationsChapter 9
Chapter SummaryRelations and Their Properties
Relations and Their Properties
Section 9.1
Section SummaryRelations and FunctionsProperties of Relations
Reflexive RelationsSymmetric and Antisymmetric RelationsTransitive Relations
Combining Relations
Binary RelationsA 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 networkFinding a feasible order for the different
phases of a complicated projectProducing 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 1st element of each ordered pair comes from A and the 2nd element comes from B
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) RIf Ahmad is also enrolled in CS111, then
(Ahmad, CS111) RIf Ali is not enrolled in CS111, then (Ali, CS111)
R
Binary RelationsExample 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 3A = {0, 1, 2} B = {a, b}
R = {(0, a), (0, b), (1, a), (2, b)} is a relation from A to B
We also canrepresent the relation from theset A to the set Bgraphically or using a table
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)}
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 2m subsets, therefore A × A has 2|A|2 subsets
there are 2|A|2 relations on a set A
Binary Relations on a Set: Example 3Which of these relations on the set of integers contain each of the pairs (1, 1), (1, 2), (2, 1), (1, -1), and (2, 2)?
R1 = {(a, b) | a ≤ b}R2 = {(a, b) | a > b}R3 = {(a, b) | a = b or a = - b}R4 = {(a, b) | a = b}R5 = {(a, b) | a = b + 1}R6 = {(a, b) | a + b ≤ 3}
(1, 1)is in R1, R3, R4, and R6
(1, 2)is in R1 and R6
(2, 1) is in R2, R5, and R6
(1, -1) is in R2, R3, and R6
(2, 2)is in R1, R3, and R4
Note that these relations are on an infinite set and each of these relations is an infinite set
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 elementa A
A= {1, 2, 3, 4}R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}R2 = {(1, 1), (1, 2), (2, 1)}R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4),
(3, 3), (3, 4), (4, 4)}R6 = {(3, 4)}
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) RIt is not irreflexive, because (1, 1) R
Properties of Relations: SymmetricRelation R on a set A is symmetric iff (b, a) R whenever (a, b) R, for all a, b ARelation 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}R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}R2 = {(1, 1), (1, 2), (2, 1)}R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3),
(3, 4), (4, 4)}R6 = {(3, 4)}
Antisymmetric Property: Example DetailsR1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}
Whenever 2nd-last column shows Yes, last column does not show Yes. R5 is not Antisymmetric
(a, b)
(b, a)
(b, a) R4?
a=b?
(1, 1)
(1, 1)
Yes Yes
(1, 2)
(2, 1)
Yes No
(2, 1)
(1, 2)
Yes No
(2, 2)
(2, 2)
Yes Yes
(3, 4)
(4, 3)
No -
(4, 1)
(1, 4)
No -
(4, 4)
(4, 4)
Yes Yes
Antisymmetric Property: Example Details
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
Whenever 2nd-last column shows Yes, last column also shows Yes. R5 is Antisymmetric
(a, b)
(b, a)
(b, a) R4?
a=b?
(2, 1)
(1, 2)
No -
(3, 1)
(1, 3)
No -
(3, 2)
(2, 3)
No -
(4, 1)
(1, 4)
No -
(4, 2)
(2, 4)
No -
(4, 3)
(3, 4)
No -
Antisymmetric Property: Example DetailsR5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}
Whenever 2nd-last column shows Yes, last column also shows Yes. R5 is Antisymmetric
(a, b)
(b, a)
(b, a) R4?
a=b?
(1, 1)
(1, 1)
Yes Yes
(1, 2)
(2, 1)
No -
(1, 3)
(3, 1)
No -
(1, 4)
(4, 1)
No -
(2, 2)
(2, 2)
Yes Yes
(2, 3)
(3, 2)
No -
(2, 4)
(4, 2)
No -
(3, 3)
(3, 3)
Yes Yes
(3, 4)
(4, 3)
No -
(4, 4)
(4, 4)
Yes Yes
Properties of Relations: TransitiveRelation 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}R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)}R2 = {(1, 1), (1, 2), (2, 1)}
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)}R6 = {(3, 4)}
Transitive Property: Example DetailsR1 = {(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 1st elements as b? Yes
Only one pair, (1, 2). Here b=1, c=2Is (a, c) a member of R1? Yes. R1 can be transitive.
Now move to the next pair, (1, 2). Here a=1, b=2.Are their pairs that have their 1st elements as b? Yes
Two pairs, (2, 1), (2, 2). Here b=2, c=1 and c=2Is (a, c) a member of R1? Yes for both c=1 and c=2. R1 may be transitive.
Now move to the next pair, (2, 1). Here a=2, b=1.Are their pairs that have their 1st elements as b? Yes
Two pairs, (1, 1), (1, 2). Here b=1, c=1 and c=2Is (a, c) a member of R1? Yes for both c=1 and c=2. R1 may be transitive.
Now move to the next pair, (2, 2). Here a=2, b=2.Are their pairs that have their 1st elements as b? Yes
Two pairs, (2, 1), (2, 2). Here b=2, c=1 and c=2Is (a, c) a member of R1? Yes for both c=1 and c=2. R1 may be transitive.
Now move to the next pair, (3, 4). Here a=3, b=4.Are their pairs that have their 1st elements as b? Yes
Two pairs, (4, 1), (4, 4). Here b=4, c=1 and c=4Is (a, c) a member of R1? No for c=1. R1 is not transitive.
Finished! No need to do any further checking.
Transitive Property: Example DetailsR4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}
There are no “No” answers in the last column. Therefore, the relation R4 is transitive.
(a, b)
Pairs with b as their 1st element
c (a, c)R4?
(2, 1)
- - -
(3, 1)
- - -
(3, 2)
(2, 1) 1 Yes
(4, 1)
- - -
(4, 2)
(2, 1) 1 Yes
(4, 3)
(3, 1)(3, 2)
12
YesYes
Properties of Relations: Summary
Reflexive aA, (a, a)R
Irreflexive aA, (a, a)R
Symmetric a,bA, (a, b)R (b, a)R
Antisymmetric
a,bA, (a, b)R (b, a)R a = b
Transitive a,b,cA, (a, b)R (b, c)R (a, c)R
Combining RelationsRelations 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},R1 = {(1, 1), (2, 2), (3, 3)}
R2 = {(1, 1), (1, 2), (1, 3), (1, 4)}
Combining Relations: Example 2R1 = {(x, y) | x < y} & R2 = {(x, y) | x > y}, where x,yR
R1 R2 = ?(x, y) R1 R2 iff (x, y) R1 or (x, y) R2
(x, y) R1 R2 iff x < y or x > yx < y or x > y implies that x yR1 R2 = {(x, y) | x y}
R1 R2 = as (x, y) cannot belong to both R1 & R2
R1 - R2 = R1
R2 - R1 = R2
R1 R2 = R1 R2 - R1 R2 = {(x, y) | x y}
x > y
x < y
y- axi
s
x-axis
x = y
R is a relation from set A to set BS 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 elementb B such that (a, b) R and (b, c) S
ExampleR 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
c
a
a b c
Composite of Relations
Powers of a RelationFor 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)} = R1
R2 = R R = {(1, 1), (2, 1), (3, 1), (4, 2)}
R3 = R
2 R = {(1, 1), (2, 1), (3, 1), (4, 1)}
R4 = R
3 R = {(1, 1), (2, 1), (3, 1), (4, 1)} = R
3
Rn = R
3 for n = 5, 6, 7, .... as well
Section 9.1: Exercises
Section 9.1: Exercises
Section 9.1: Exercises
Section 9.1: Exercises
Section 9.1: Exercises