23
CSNB143 – Discrete Structure Topic 7 – Relations Part II

CSNB143 – Discrete Structure Topic 7 – Relations Part II

Embed Size (px)

Citation preview

Page 1: CSNB143 – Discrete Structure Topic 7 – Relations Part II

CSNB143 – Discrete Structure

Topic 7 – Relations Part II

Page 2: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsLearning Outcomes• Student should be able to know how relation is being built• Students should be able to apply relation and combine the knowledge

with other topics in this subject.

Page 3: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsPath in Relation

Page 4: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsPath in Relation• A relation Rn on A : x Rn y means there is a path of length n from x to y in R• Example:

Page 5: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsReachability • is a concept in which there is a relation between x and y in whatever

length possible.• Written as x R y where x and y have relations.• Example: Find R for R = { (a,a), (a,b), (b,c), (c,e), (c,d), (d,e)}

Page 6: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsProperties of relations - Reflexive• Let say A = {1, 2, 3}

• Reflexive: All elements have relation to itselves.

• Set: {(1, 1), (2, 2), (3, 3,)}

• Matrix: Values on its diagonal are all 1.

• Diagraph: There must have cycle length 1 on each vertex.

Page 7: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsProperties of relations - Irreflexive

• Let say A = {1, 2, 3}

• Set: U – R

• Matrix: All values on its diagonal is 0..

• Diagraph: Diagraph: There is no cycle length 1 on each vertex

Page 8: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsProperties of relations - Symmetric

• If a = b, a R b, b R a (allowed), if a b, a R b, b R a• Set: {(1, 1), (1, 2), (2, 1), (2, 3), (3, 2)}• Matrix: Values symmetrical on the diagonal are either both 0 or 1.

• Diagraph: Two-way relation. Cycle length 1 is allowed.

Page 9: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsProperties of relations - Asymmetric

• Asymmetric: If a b, a R b or b R a• Set: {(1, 2), (1, 3), (2, 3)}• Matrix: Values not symmetrical on the diagonal. Diagonal entries must all

be 0.

• Diagraph: No two-way and no cycle length 1 for all vertex.

Page 10: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsProperties of relations – Antisymmetric

• Antisymmetric: If a R b, b R a, then a = b, if a b, a R b or b R a.• Set: {(1, 1), (1, 2), (1, 3), (2, 3), (3, 3)}• Matrix: Values not symmetrical on the diagonal.

• Diagraph: No two-way. Cycle length 1 is allowed

Page 11: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsExercise:

Page 12: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsExercise

Page 13: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsTransitive RelationDefinition:• In mathematics, a relation R on a set X is transitive if whenever an element a

is related to an element b, and b is in turn related to an element c, then a is also related to c.

• For example, "is greater than," "is at least as great as," and "is equal to“ are transitive relations:whenever A > B and B > C, then also A > C whenever A ≥ B and B ≥ C, then also A ≥ C whenever A = B and B = C, then also A = C

• On the other hand, "is the mother of" is not a transitive relation, because if Alice is the mother of Brenda, and Brenda is the mother of Claire, then Alice is not the mother of Claire. What is more, it is not transitive:

Alice can never be the mother of Claire.

Page 14: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsTransitive Closure• Let R be a relation on set A and R is not transitive. So we want to make it

becomes transitive.• Let R be a relation on set A. Then R is a transitive closure for R.

Page 15: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsTransitive Closure (R )Ways to find the transitive closure for R1. Matrix Product Matrix product require us to times MR few times until the final outcome

is the same with the previous outcome.

Page 16: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsTransitive Closure2. Warshall Algorithm • This algorithm only can be done to a square matrix n x n. The process must be done n times.• Steps involved are:

– Bring down all entries value 1 from Wk-1 to Wk.

– List all location p1, p2, … in column k for Wk-1 in which the entries is 1, and all location q1, q2, … in row k for Wk-1, in which the entries is 1.

– Put all 1 in all location pi, qj for Wk (if the entries is 0).

Page 17: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsImplementing Warshall AlgorithmFind the transitive closure for MR

Page 18: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsFind the transitive closure for MR

Step 2

Step 3

Page 19: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsFind the transitive closure for MR

Step 4

Step 3

Page 20: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – Relations

Independent Reading

Page 21: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – Relations

Page 22: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsComposition• Let say there are 3 sets A, B and C where R is a relation from A to B and S is a

relation from B to C.• A new relation, named composition can be build, written as S R.• Relation S R is a relation from A to C, defined as: • If (a A) and (c C), then a (S R) c if and only if (b B), and there exist a R b

and b S c.• Example: Let A = {1, 2, 3, 4}.

R = {(1, 2), (1, 1), (1, 3), (2, 4), (3, 2)} andS = {(1, 4), (1, 3), (2, 3), (3, 1), (4, 1)}. Find S R.

• Ans: In R we find that (1, 2) R and (2, 3) S, then we must have (1, 3) S R. using this method, we can find that S R = {(1, 3), (1, 4), (1, 1), (2, 1), (3, 3)}

Page 23: CSNB143 – Discrete Structure Topic 7 – Relations Part II

Topic 7 – RelationsClosure• If R is a relation on set A, R might show less few elements in which R is not

fulfilling the important properties such as reflexive, symmetric and transitive.• We might want to and as minimum as possible, new elements in order to

make R meets the criteria.• The smallest relation R1, in the relation that contains R and the new elements

together so that R1 will meets the criteria.

• In this case, we call R1 as a closure of R.

• Example: Let A ={a, b, c} and R = {(a, a), (a, b), (b, c), (a, c)}. Then The reflexive closure for R is R1 = {(a, a), (a, b), (b, c), (a, c), (b, b), (c, c)}.

And, symmetric closure for R is R1 = {(a, a), (a, b), (b, a), (b, c), (c, b), (a, c), (c, a)}