Successfully reported this slideshow.
Upcoming SlideShare
×

of

Upcoming SlideShare
Countdown Class 6th Mathematics Chapter 13 Solution
Next

66

Share

# Chapter 9 Relations in Discrete Mathematics

What is a Relation
Representing relations
Functions as Relations
Relations on a Set
Relation properties
Combining Relations
Databases and Relations
Representing Relations Using Matrices
Equivalence Classes

See all

See all

### Chapter 9 Relations in Discrete Mathematics

1. 1. Discrete MathematicsDiscrete Mathematics and Itsand Its ApplicationsApplications Seventh EditionSeventh Edition Chapter 9Chapter 9 RelationsRelations Lecture Slides By Adil AslamLecture Slides By Adil Aslam mailto:adilaslam5959@gmail.commailto:adilaslam5959@gmail.com
2. 2. IntroductionIntroduction Relationships between elements of setsRelationships between elements of sets are represented using the structureare represented using the structure called acalled a relationrelation.. – Relationship between a program and itsRelationship between a program and its variablesvariables – Pairs of cities linked by airline flights in aPairs of cities linked by airline flights in a networknetwork
3. 3. RelationsRelations The most direct way to express a relationshipThe most direct way to express a relationship between elements of two sets is to usebetween elements of two sets is to use orderedordered pairs.pairs. For this reason, sets of ordered pairs areFor this reason, sets of ordered pairs are calledcalled binary relationsbinary relations.. Definition: Let A and B be sets. A binary relation from A to B is a subset R of A× B = { (a, b) : a∈A, b∈B }.
4. 4. RelationRelation In other words, for a binary relation R weIn other words, for a binary relation R we have Rhave R ⊆⊆ AA××B. We use the notation aRb toB. We use the notation aRb to denote that (a, b)denote that (a, b)∈∈R and aR and aRb to denote thatb to denote that (a, b)(a, b)∉∉R.R. When (a, b) belongs to R, a is said to beWhen (a, b) belongs to R, a is said to be relatedrelated to b by Rto b by R
5. 5. Example 1Example 1 LetLet AA be the set of students andbe the set of students and BB be thebe the set of coursesset of courses LetLet RR be the relation that consists of thosebe the relation that consists of those pairs (a, b) where apairs (a, b) where a ∊A∊A and band b ∊∊BB IfIf JasonJason is enrolled only inis enrolled only in CSE20CSE20, and, and JohnJohn is enrolled inis enrolled in CSE20CSE20 andand CSE21CSE21 TheThe pairspairs (Jason, CSE20), (John,CSE20),(Jason, CSE20), (John,CSE20), (John, CSE 21) belong to R(John, CSE 21) belong to R ButBut (Jason, CSE21) does not belong to R(Jason, CSE21) does not belong to R
6. 6. Example 2Example 2 LetLet AA be the students in a the CS majorbe the students in a the CS major • AA = {Alice, Bob, Claire, Dan}= {Alice, Bob, Claire, Dan} LetLet BB be the courses the departmentbe the courses the department offersoffers • BB = {CS101, CS201, CS202}= {CS101, CS201, CS202} We specify relationWe specify relation RR == AA ×× BB as the setas the set that lists all studentsthat lists all students aa ∈∈ AA enrolled inenrolled in classclass bb ∈∈ BB R = { (Alice, CS101), (Bob, CS201), (Bob,R = { (Alice, CS101), (Bob, CS201), (Bob, CS202),(Dan, CS201), (Dan, CS202) }CS202),(Dan, CS201), (Dan, CS202) }
7. 7. Representing relationsRepresenting relations CS101 CS201 CS202 Alice Bob Claire Dan CS101 CS201 CS202 Alice X Bob X X Claire Dan X X We can represent relations graphically: We can represent relations in a table: Not valid functions!
8. 8. Example 3Example 3 0 1 2 a b A B R R ⊆ A×B = { (0,a) , (0,b) , (1,a) (1,b) , (2,a) , (2,b)} ∈R ∈R Example 3 Let A={0, 1, 2} and B={a, b}, then {(0,a), (0,b),(1,a),(2,b)} is a relation R from A to B. This means, for instance, that 0Ra, but that 1Rb.
9. 9. Functions as RelationsFunctions as Relations You might remember that aYou might remember that a functionfunction f from a set Af from a set A to a set B assigns a unique element of B to eachto a set B assigns a unique element of B to each element of A.element of A. TheThe graphgraph of f is the set of ordered pairs (a, b)of f is the set of ordered pairs (a, b) such that b = f(a).such that b = f(a). Since the graph of f is a subset of ASince the graph of f is a subset of A××B, it is aB, it is a relationrelation from A to B.from A to B. Moreover, for each elementMoreover, for each element aa of A, there isof A, there is exactly one ordered pair in the graph that hasexactly one ordered pair in the graph that has aa asas its first element.its first element.
10. 10. Functions as RelationsFunctions as Relations Conversely, if R is a relation from A to B such thatConversely, if R is a relation from A to B such that every element in A is the first element of exactlyevery element in A is the first element of exactly one ordered pair of R, then a function can beone ordered pair of R, then a function can be defined with R as its graph.defined with R as its graph. This is done by assigning to an element aThis is done by assigning to an element a∈∈A theA the unique element bunique element b∈∈B such that (a, b)B such that (a, b)∈∈R.R.
11. 11. Relations on a SetRelations on a Set Definition:Definition: A relation on the set A is a relationA relation on the set A is a relation from A to A.from A to A. In other words, a relation on the set A is a subsetIn other words, a relation on the set A is a subset of Aof A××A.A. Example:Example: Let A = {1, 2, 3, 4}. Which ordered pairsLet A = {1, 2, 3, 4}. Which ordered pairs are in the relation R = {(a, b) | a < b} ?are in the relation R = {(a, b) | a < b} ?
12. 12. Relations on a SetRelations on a Set Solution:Solution: R = {R = {(1, 2),(1, 2), (1, 3),(1, 3), (1, 4),(1, 4), (2, 3),(2, 3),(2, 4),(2, 4),(3, 4)}(3, 4)} RR 11 22 33 44 11 22 33 44 11 11 22 33 44 22 33 44 XX XX XX XX XX XX
13. 13. Example 2Example 2 LetLet AA be the setbe the set {1, 2, 3, 4}{1, 2, 3, 4}. Which ordered pairs. Which ordered pairs are in the relationare in the relation RR = { (= { (aa,, bb)|)| aa dividesdivides bb }}?? Sol :Sol : 1 2 3 4 1 2 3 4 R = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,4),(3,3),(4,4) } Since (a, b) is in R if and only if a and b are positive integers not exceeding 4 such that a divides b
14. 14. ExampleExample How many relations are there on a set with nHow many relations are there on a set with n elements?elements? A relation on a set A is a subset of A x A.A relation on a set A is a subset of A x A. As A x A has nAs A x A has n22 elements, there are 2elements, there are 2nn22 Subsets.Subsets. Thus there are 2Thus there are 2nn22 relations on a set with nrelations on a set with n elementselements That is, there are 2That is, there are 23322 = 2= 299 = 512 relations on= 512 relations on the set {a, b, c}the set {a, b, c}
15. 15. Relation propertiesRelation properties Six properties of relations we willSix properties of relations we will study:study: – ReflexiveReflexive – IrreflexiveIrreflexive – SymmetricSymmetric – AsymmetricAsymmetric – AntisymmetricAntisymmetric – TransitiveTransitive
16. 16. ReflexivityReflexivity In some relations an element is alwaysIn some relations an element is always related to itselfrelated to itself Let R be the relation on the set of all peopleLet R be the relation on the set of all people consisting of pairs (x,y) where x and y haveconsisting of pairs (x,y) where x and y have the same mother and the same father. Thenthe same mother and the same father. Then x R x for every person xx R x for every person x Definition:Definition: A relation R on a set A is calledA relation R on a set A is called reflexivereflexive if (a, a)if (a, a)∈∈R for every element aR for every element a∈∈A.A.
17. 17. ReflexivityReflexivity Examples of reflexive relations:Examples of reflexive relations: – =, ≤, ≥=, ≤, ≥ Examples of relations that are notExamples of relations that are not reflexive:reflexive: – <, ><, >
18. 18. ExamplesExamples R = {(1, 1), (1, 2), (2, 3), (3, 3), (4, 4)}R = {(1, 1), (1, 2), (2, 3), (3, 3), (4, 4)} No.No. R = {(1, 1), (2, 2), (2, 3), (3, 3), (4, 4)}R = {(1, 1), (2, 2), (2, 3), (3, 3), (4, 4)} Yes.Yes. R = {(1, 1), (2, 2), (3, 3)}R = {(1, 1), (2, 2), (3, 3)} No.No.
19. 19. ExampleExample Example:Example: Consider the following relations onConsider the following relations on {1, 2, 3, 4}{1, 2, 3, 4} RR11 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)}= {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)} RR22 = {(1,1), (1,2), (2,1)}= {(1,1), (1,2), (2,1)} RR33 = {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (3,4), (4,1),= {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (3,4), (4,1), (4,4)}(4,4)} RR44 = {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)}= {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)} RR55 = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3),= {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)}(3,4), (4,4)} RR66 = {(3,4)}= {(3,4)} Which of these relations are reflexive?Which of these relations are reflexive?
20. 20. SolutionSolution RR33 and Rand R55: reflexive: reflexive ⇐⇐ both contain all pairsboth contain all pairs of the form (a, a): (1,1), (2,2), (3,3) & (4,4).of the form (a, a): (1,1), (2,2), (3,3) & (4,4). RR11, R, R22, R, R44 and Rand R66: not reflexive: not reflexive ⇐⇐ not containnot contain all of these ordered pairs. (3,3) is not inall of these ordered pairs. (3,3) is not in any of these relations.any of these relations. 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), (3,4), (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)}
21. 21. ExampleExample EXAMPLE:EXAMPLE: Let A = {1, 2, 3, 4} and define relations R1,R2,Let A = {1, 2, 3, 4} and define relations R1,R2, R3, R4 on A as follows:R3, R4 on A as follows: – R1 = {(1, 1), (3, 3), (2, 2), (4, 4)}R1 = {(1, 1), (3, 3), (2, 2), (4, 4)} – R2 = {(1, 1), (1, 4), (2, 2), (3, 3), (4, 3)}R2 = {(1, 1), (1, 4), (2, 2), (3, 3), (4, 3)} – R3 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}R3 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)} – R4 = {(1, 3), (2, 2), (2, 4), (3, 1), (4, 4)}R4 = {(1, 3), (2, 2), (2, 4), (3, 1), (4, 4)} – Then,Then, – R1 is reflexive, since (a, a)R1 is reflexive, since (a, a) ∈∈R1 for all aR1 for all a ∈∈A.A. – R2 is not reflexive, because (4, 4)R2 is not reflexive, because (4, 4) ∉∉R2.R2. – R3 is reflexive, since (a, a)R3 is reflexive, since (a, a) ∈∈R3 for all aR3 for all a ∈∈A.A. – R4 is not reflexive, because (1, 1)R4 is not reflexive, because (1, 1) ∉∉R4, (3, 3)R4, (3, 3) ∉∉R4R4
22. 22. Directed Graph Of A ReflexiveDirected Graph Of A Reflexive RelationRelation The directed graph of every reflexive relationThe directed graph of every reflexive relation includes an arrow from every point to theincludes an arrow from every point to the point itself (i.e., a loop).point itself (i.e., a loop). EXAMPLEEXAMPLE :: Let A = {1, 2, 3, 4} and define relations R1,Let A = {1, 2, 3, 4} and define relations R1, R2,R2, R3, and R4 on A byR3, and R4 on A by – R1 = {(1, 1), (3, 3), (2, 2), (4, 4)}R1 = {(1, 1), (3, 3), (2, 2), (4, 4)} – R2 = {(1, 1), (1, 4), (2, 2), (3, 3), (4, 3)}R2 = {(1, 1), (1, 4), (2, 2), (3, 3), (4, 3)} – R3 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)}R3 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)} – R4 = {(1, 3), (2, 2), (2, 4), (3, 1), (4, 4)}R4 = {(1, 3), (2, 2), (2, 4), (3, 1), (4, 4)} Then their directed graphs areThen their directed graphs are
23. 23. R1 = {(1, 1), (3, 3), (2, 2), (4, 4)} R2 = {(1, 1), (1, 4), (2, 2), (3, 3), (4, 3)} Directed Graphs Are
24. 24. Directed Graphs AreDirected Graphs Are R3 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (4, 4)} R4 = {(1, 3), (2, 2), (2, 4), (3, 1), (4, 4)}
25. 25. Your TaskYour Task For each of these relations on the set{1,2,3,4},For each of these relations on the set{1,2,3,4}, decide Whether it is reflexivedecide Whether it is reflexive a) {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)}a) {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} b){(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)}b){(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)} c) {(2,4), (4,2)}c) {(2,4), (4,2)} d){(1,2), (2,3), (3,4)}d){(1,2), (2,3), (3,4)} e) {(1,1), (2,2), (3,3),(4,4)}e) {(1,1), (2,2), (3,3),(4,4)} f) {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4)f) {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4) Solution: b and e
26. 26. Matrix Representation Of AMatrix Representation Of A Reflexive RelationReflexive Relation • Let A = {a1, a2, …, an}. A Relation R on A isLet A = {a1, a2, …, an}. A Relation R on A is reflexive if and only if (ai, ai)reflexive if and only if (ai, ai) ∈∈RR ∀∀ i=1,2, …,n.i=1,2, …,n. • Accordingly, R isAccordingly, R is reflexivereflexive if all the elementsif all the elements on theon the main diagonalmain diagonal of theof the matrixmatrix MM representing R are equal to 1.representing R are equal to 1. • The relation R = {(1,1), (1,3), (2,2), (3,2),The relation R = {(1,1), (1,3), (2,2), (3,2), (3,3)} on A = {1,2,3} represented by the(3,3)} on A = {1,2,3} represented by the following matrix M, is reflexive.following matrix M, is reflexive.
27. 27. irreflexiveirreflexive A relation is irreflexive if every element isA relation is irreflexive if every element is notnot related to itselfrelated to itself – Or, (Or, (aa,,aa))∉∉RR – Irreflexivity is the opposite of reflexivityIrreflexivity is the opposite of reflexivity Examples of irreflexive relations:Examples of irreflexive relations: – <, ><, > Examples of relations that are notExamples of relations that are not irreflexive:irreflexive: – =, ≤, ≥=, ≤, ≥
28. 28. SymmetricSymmetric Definitions:Definitions: A relation R on a set A is calledA relation R on a set A is called symmetricsymmetric if (b,if (b, a)a)∈∈R whenever (a, b)R whenever (a, b)∈∈R for all a, bR for all a, b∈∈A.A. A relation R on a set A is calledA relation R on a set A is called antisymmetricantisymmetric ifif a = b whenever (a, b)a = b whenever (a, b)∈∈R and (b, a)R and (b, a)∈∈R.R.
29. 29. SymmetricSymmetric A relation is symmetric if, for every (A relation is symmetric if, for every (aa,,bb))∈∈RR,, then (then (bb,,aa))∈∈RR Examples of symmetric relations:Examples of symmetric relations: – =, isTwinOf()=, isTwinOf() Examples of relations that are notExamples of relations that are not symmetric:symmetric: – <, >, ≤, ≥<, >, ≤, ≥
30. 30. AntisymmetricAntisymmetric A relation is antisymmetric if, forA relation is antisymmetric if, for every (every (aa,,bb))∈∈RR, then (, then (b,ab,a))∈∈RR is trueis true only whenonly when aa==bb – Antisymmetry isAntisymmetry is notnot the opposite of symmetrythe opposite of symmetry Examples of antisymmetric relations:Examples of antisymmetric relations: – =, ≤, ≥=, ≤, ≥ Examples of relations that are notExamples of relations that are not antisymmetric:antisymmetric: – <, >, isTwinOf()<, >, isTwinOf()
31. 31. AsymmetricAsymmetric A relation is asymmetric if, for everyA relation is asymmetric if, for every ((aa,,bb))∈∈RR, then (, then (b,ab,a))∉∉RR – Asymmetry is the opposite of symmetryAsymmetry is the opposite of symmetry Examples of asymmetric relations:Examples of asymmetric relations: – <, ><, > Examples of relations that are notExamples of relations that are not asymmetric:asymmetric: – =, isTwinOf(), ≤, ≥=, isTwinOf(), ≤, ≥
32. 32. ExampleExample Example:Example: Consider the following relations onConsider the following relations on {1, 2, 3, 4}{1, 2, 3, 4} RR11 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)}= {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)} RR22 = {(1,1), (1,2), (2,1)}= {(1,1), (1,2), (2,1)} RR33 = {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (3,4), (4,1),= {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (3,4), (4,1), (4,4)}(4,4)} RR44 = {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)}= {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)} RR55 = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3),= {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)}(3,4), (4,4)} RR66 = {(3,4)}= {(3,4)} Which of these relations are symmetric and whichWhich of these relations are symmetric and which are antisymmetric?are antisymmetric?
33. 33. SolutionSolution RR22 & R& R33: symmetric: symmetric ⇐⇐ each case (b, a) belongs to theeach case (b, a) belongs to the relation whenever (a, b) does.relation whenever (a, b) does. For RFor R22: only thing to check that both (1,2) & (2,1): only thing to check that both (1,2) & (2,1) belong to the relationbelong to the relation For RFor R33: it is necessary to check that both (1,2) &: it is necessary to check that both (1,2) & (2,1) belong to the relation.(2,1) belong to the relation. None of the other relations is symmetric: find a pairNone of the other relations is symmetric: find a pair (a, b) so that it is in the relation but (b, a) is not.(a, b) so that it is in the relation but (b, a) is not. 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)}
34. 34. SolutionSolution RR44, R, R55 and Rand R66: antisymmetric: antisymmetric ⇐⇐for each of thesefor each of these relations there is no pair of elements a and b withrelations there is no pair of elements a and b with aa ≠≠ b such that both (a, b) and (b, a) belong to theb such that both (a, b) and (b, a) belong to the relation.relation. None of the other relations is antisymmetric.: find aNone of the other relations is antisymmetric.: find a pair (a, b) with apair (a, b) with a ≠≠ b so that (a, b) and (b, a) are bothb so that (a, b) and (b, a) are both in the relation.in the relation. 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)}
35. 35. ExampleExample Which are symmetric and antisymmetricWhich are symmetric and antisymmetric RR11={(a,b)|a≤b}={(a,b)|a≤b} RR22={(a,b)|a>b}={(a,b)|a>b} RR33={(a,b)|a=b or a=-b}={(a,b)|a=b or a=-b} RR44={(a,b)|a=b}={(a,b)|a=b} RR55={(a,b)|a=b+1}={(a,b)|a=b+1} RR66={(a,b)|a+b≤3}={(a,b)|a+b≤3} SymmetricSymmetric: R: R33, R, R44,, RR66. R. R33 is symmetric, if a=b (or a=-b), then b=ais symmetric, if a=b (or a=-b), then b=a (b=-a), R(b=-a), R44 is symmetric as a=b implies b=a, Ris symmetric as a=b implies b=a, R66 is symmetric asis symmetric as a+b≤3 implies b+a≤3a+b≤3 implies b+a≤3 AntisymmetricAntisymmetric: R: R11, R, R22,, RR44,, RR55 . R. R11 is antisymmetric as a≤b and b≤ais antisymmetric as a≤b and b≤a imply a=b. Rimply a=b. R22 is antisymmetric as it is impossible to have a>b andis antisymmetric as it is impossible to have a>b and b>a, Rb>a, R44 is antisymmteric as two elements are related w.r.t. Ris antisymmteric as two elements are related w.r.t. R44 ifif and only if they are equal. Rand only if they are equal. R55 is antisymmetric as it is impossibleis antisymmetric as it is impossible
36. 36. SymmetricSymmetric Let A = {1, 2, 3, 4} and define relations R1,Let A = {1, 2, 3, 4} and define relations R1, R2,R2, R3, and R4on A as follows.R3, and R4on A as follows. – R1 = {(1, 1), (1, 3), (2, 4), (3, 1), (4,2)}R1 = {(1, 1), (1, 3), (2, 4), (3, 1), (4,2)} – R2 = {(1, 1), (2, 2), (3, 3), (4, 4)}R2 = {(1, 1), (2, 2), (3, 3), (4, 4)} – R3 = {(2, 2), (2, 3), (3, 4)}R3 = {(2, 2), (2, 3), (3, 4)} – R4 = {(1, 1), (2, 2), (3, 3), (4, 3), (4, 4)}R4 = {(1, 1), (2, 2), (3, 3), (4, 3), (4, 4)} • Then R1 is symmetric because for every order pairThen R1 is symmetric because for every order pair (a,b) in R1, we have (b,a) in R1, for example we have(a,b) in R1, we have (b,a) in R1, for example we have (1,3) in R1 then we have (3,1) in R1. similarly all other(1,3) in R1 then we have (3,1) in R1. similarly all other ordered pairs can be checked.ordered pairs can be checked. • R2 is also symmetric.R2 is also symmetric. • R3 is not symmetric, because (2,3)R3 is not symmetric, because (2,3) ∈∈ R3 but (3,2)R3 but (3,2) ∉∉ R3.R3.
37. 37. Directed Graph Of A SymmetricDirected Graph Of A Symmetric RelationRelation For a symmetric directed graph whenever thereFor a symmetric directed graph whenever there is an arrow going from one point of the graph tois an arrow going from one point of the graph to a second, there is an arrow going from thea second, there is an arrow going from the second point back to the first.second point back to the first. EXAMPLEEXAMPLE – Let A = {1, 2, 3, 4} and define relations R1, R2, R3,Let A = {1, 2, 3, 4} and define relations R1, R2, R3, and R4 on A by the directed graphs:and R4 on A by the directed graphs: • R1 = {(1, 1), (1, 3), (2, 4), (3, 1), (4,2)}R1 = {(1, 1), (1, 3), (2, 4), (3, 1), (4,2)} • R2 = {(1, 1), (2, 2), (3, 3), (4, 4)}R2 = {(1, 1), (2, 2), (3, 3), (4, 4)} • R3 = {(2, 2), (2, 3), (3, 4)}R3 = {(2, 2), (2, 3), (3, 4)} • R4= {(1, 1), (2, 2), (3, 3), (4, 3), (4, 4)}R4= {(1, 1), (2, 2), (3, 3), (4, 3), (4, 4)}
38. 38. Directed Graph Of A SymmetricDirected Graph Of A Symmetric RelationRelation
39. 39. Directed Graph Of A SymmetricDirected Graph Of A Symmetric RelationRelation
40. 40. Matrix Representation Of AMatrix Representation Of A Symmetric RelationSymmetric Relation • Let A = {a1, a2, …, an}.Let A = {a1, a2, …, an}. • A relation R on A is symmetric if and only ifA relation R on A is symmetric if and only if for all ai, ajfor all ai, aj ∈∈ A, if (ai, aj)A, if (ai, aj) ∈∈R then (aj,R then (aj, ai)ai)∈∈R.R. • Accordingly, R is symmetric if the elementsAccordingly, R is symmetric if the elements in the ith row are the same as the elementsin the ith row are the same as the elements in the ith column of the matrix Min the ith column of the matrix M representing R.representing R. • The relation R = {(1,3), (2,2), (3,1), (3,3)} onThe relation R = {(1,3), (2,2), (3,1), (3,3)} on A = {1,2,3} represented by the followingA = {1,2,3} represented by the following matrix M is symmetric.matrix M is symmetric.
41. 41. Matrix Representation Of AMatrix Representation Of A Symmetric RelationSymmetric Relation
42. 42. Your TaskYour Task For each of these relations on theFor each of these relations on the set{1,2,3,4},decide Whether it is Symmetric,set{1,2,3,4},decide Whether it is Symmetric, Antisymmetric.Antisymmetric. a) {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)}a) {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} b){(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)}b){(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)} c) {(2,4), (4,2)}c) {(2,4), (4,2)} d){(1,2), (2,3), (3,4)}d){(1,2), (2,3), (3,4)} e) {(1,1), (2,2), (3,3),(4,4)}e) {(1,1), (2,2), (3,3),(4,4)} f) {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4)f) {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4) Symmetric: b , c ,e Antisymmetric: d , e
43. 43. TransitiveTransitive Definition:Definition: A relation R on a set A is calledA relation R on a set A is called transitivetransitive if whenever (a, b)if whenever (a, b)∈∈R and (b, c)R and (b, c)∈∈R,R, then (a, c)then (a, c)∈∈R for a, b, cR for a, b, c∈∈A.A. IfIf aa << bb andand bb << cc, then, then aa << cc – Thus, < is transitiveThus, < is transitive IfIf aa == bb andand bb == cc, then, then aa == cc – Thus, = is transitiveThus, = is transitive
44. 44. ExampleExample Example:Example: Consider the following relations onConsider the following relations on {1, 2, 3, 4}{1, 2, 3, 4} RR11 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)}= {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)} RR22 = {(1,1), (1,2), (2,1)}= {(1,1), (1,2), (2,1)} RR33 = {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (3,4), (4,1),= {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (3,4), (4,1), (4,4)}(4,4)} RR44 = {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)}= {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)} RR55 = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3),= {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)}(3,4), (4,4)} RR66 = {(3,4)}= {(3,4)} Which of these relations are transitive?Which of these relations are transitive?
45. 45. SolutionSolution  RR44 , R, R55 & R& R66 : transitive: transitive ⇐⇐ verify that if (a, b) andverify that if (a, b) and (b, c) belong to this relation then (a, c) belongs(b, c) belong to this relation then (a, c) belongs also to the relationalso to the relation RR44 transitive since (3,2) and (2,1), (4,2) and (2,1),transitive since (3,2) and (2,1), (4,2) and (2,1), (4,3) and (3,1), and (4,3) and (3,2) are the only(4,3) and (3,1), and (4,3) and (3,2) are the only such sets of pairs, and (3,1) , (4,1) and (4,2)such sets of pairs, and (3,1) , (4,1) and (4,2) belong to Rbelong to R44.. Same reasoning for RSame reasoning for R55 and Rand R66..  RR11 : not transitive: not transitive ⇐⇐ (3,4) and (4,1) belong to R(3,4) and (4,1) belong to R11,, but (3,1) does not.but (3,1) does not.  RR22 : not transitive: not transitive ⇐⇐ (2,1) and (1,2) belong to R(2,1) and (1,2) belong to R22,, but (2,2) does not.but (2,2) does not.  RR33 : not transitive: not transitive ⇐⇐ (4,1) and (1,2) belong to R(4,1) and (1,2) belong to R33,, but (4,2) does not.but (4,2) does not.
46. 46. TransitiveTransitive EXAMPLEEXAMPLE – Let A = {1, 2, 3, 4} and define relations R1, R2 andLet A = {1, 2, 3, 4} and define relations R1, R2 and R3 on A as follows:R3 on A as follows: – R1 = {(1, 1), (1, 2), (1, 3), (2, 3)}R1 = {(1, 1), (1, 2), (1, 3), (2, 3)} – R2 = {(1, 2), (1, 4), (2, 3), (3, 4)}R2 = {(1, 2), (1, 4), (2, 3), (3, 4)} – R3 = {(2, 1), (2, 4), (2, 3), (3,4)}R3 = {(2, 1), (2, 4), (2, 3), (3,4)} – Then R1 is transitive because (1, 1), (1, 2) are in RThen R1 is transitive because (1, 1), (1, 2) are in R then to be transitive relation (1,2) must be therethen to be transitive relation (1,2) must be there and it belongs to R Similarly for other order pairs.and it belongs to R Similarly for other order pairs. – R2 is not transitive since (1,2) and (2,3)R2 is not transitive since (1,2) and (2,3) ∈∈ R2 butR2 but (1,3)(1,3) ∉∉ R2.R2. – R3 is transitive.R3 is transitive.
47. 47. Directed Graph Of A TransitiveDirected Graph Of A Transitive RelationRelation For a transitive directed graph, wheneverFor a transitive directed graph, whenever there is an arrow going from one point to thethere is an arrow going from one point to the second, and from the second to the third,second, and from the second to the third, there is an arrow going directly from thethere is an arrow going directly from the first to the third.first to the third. EXAMPLEEXAMPLE – Let A = {1, 2, 3, 4} and define relations R1, R2Let A = {1, 2, 3, 4} and define relations R1, R2 and R3 on A by the directed graphs:and R3 on A by the directed graphs: – R1 = {(1, 1), (1, 2), (1, 3), (2, 3)}R1 = {(1, 1), (1, 2), (1, 3), (2, 3)} – R2 = {(1, 2), (1, 4), (2, 3), (3, 4)}R2 = {(1, 2), (1, 4), (2, 3), (3, 4)} – R3 = {(2, 1), (2, 4), (2, 3), (3,4)}R3 = {(2, 1), (2, 4), (2, 3), (3,4)}
48. 48. Directed Graph Of A TransitiveDirected Graph Of A Transitive RelationRelation
49. 49. Your TaskYour Task For each of these relations on theFor each of these relations on the set{1,2,3,4},decide Whether it is transitiveset{1,2,3,4},decide Whether it is transitive .. a) {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)}a) {(2,2), (2,3), (2,4), (3,2), (3,3), (3,4)} b){(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)}b){(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)} c) {(2,4), (4,2)}c) {(2,4), (4,2)} d){(1,2), (2,3), (3,4)}d){(1,2), (2,3), (3,4)} e) {(1,1), (2,2), (3,3),(4,4)}e) {(1,1), (2,2), (3,3),(4,4)} f) {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4)f) {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4) Transitive : a , b , e
50. 50. Counting RelationsCounting Relations Example:Example: How many different reflexive relationsHow many different reflexive relations can be defined on a set A containing n elements?can be defined on a set A containing n elements? Solution:Solution: Relations on R are subsets of ARelations on R are subsets of A××A, whichA, which contains ncontains n22 elements.elements. Therefore, different relations on A can beTherefore, different relations on A can be generated by choosing different subsets out ofgenerated by choosing different subsets out of these nthese n22 elements, so there are 2elements, so there are 2nn22 relations.relations. AA reflexivereflexive relation, however,relation, however, mustmust contain the ncontain the n elements (a, a) for every aelements (a, a) for every a∈∈A.A. Consequently, we can only choose among nConsequently, we can only choose among n22 – n =– n = n(n – 1) elements to generate reflexive relations, son(n – 1) elements to generate reflexive relations, so there are 2there are 2n(n – 1)n(n – 1) of them.of them.
51. 51. Relations of relations summaryRelations of relations summary = < > ≤ ≥ Reflexive X X X Irreflexive X X Symmetric X Asymmetric X X Antisymmetric X X X Transitive X X X X X
52. 52. Combining RelationsCombining Relations Relations are sets, and therefore, we can apply theRelations are sets, and therefore, we can apply the usualusual set operationsset operations to them.to them. If we have two relations RIf we have two relations R11 and Rand R22, and both of, and both of them are from a set A to a set B, then we canthem are from a set A to a set B, then we can combine them to Rcombine them to R11 ∪∪ RR22, R, R11 ∩∩ RR22, or R, or R11 – R– R22.. In each case, the result will beIn each case, the result will be another relationanother relation from A to Bfrom A to B..
53. 53. ExampleExample Let A = {1, 2, 3} and B = {1, 2, 3, 4, }.Let A = {1, 2, 3} and B = {1, 2, 3, 4, }. The relationsThe relations RR11 = {(1,1), (2,2), (3,3)} and= {(1,1), (2,2), (3,3)} and RR22 = {(1,1), (1,2), (1,3), (1,4)}= {(1,1), (1,2), (1,3), (1,4)} can be combined to obtain:can be combined to obtain: Solution:Solution: RR11 ∪∪ RR22 = {(1,1), (1,2), (1,3), (1,4), (2,2), (3,3)}= {(1,1), (1,2), (1,3), (1,4), (2,2), (3,3)} RR11 ∩∩ RR22 = {(1,1)}= {(1,1)} RR11 – R– R22 = {(2,2), (3,3)}= {(2,2), (3,3)} RR22 – R– R11 = {(1,2), (1,3), (1,4)}= {(1,2), (1,3), (1,4)}
54. 54. Combining RelationsCombining Relations …… and there is another important way to combineand there is another important way to combine relations.relations. Definition:Definition: Let R be a relation from a set A to aLet R be a relation from a set A to a set B and S a relation from B to a set C. Theset B and S a relation from B to a set C. The compositecomposite of R and S is the relation consisting ofof R and S is the relation consisting of ordered pairs (a, c), where aordered pairs (a, c), where a∈∈A, cA, c∈∈C, and for whichC, and for which there exists an element bthere exists an element b∈∈B such that (a, b)B such that (a, b)∈∈R andR and (b, c)(b, c)∈∈S. We denote the composite of R and S byS. We denote the composite of R and S by SS°° RR.. In other words, if relation R contains a pair (a, b)In other words, if relation R contains a pair (a, b) and relation S contains a pair (b, c), then Sand relation S contains a pair (b, c), then S°° RR contains a pair (a, c).contains a pair (a, c).
55. 55. ExampleExample What is the composite of the relations R and S whereWhat is the composite of the relations R and S where R is the relation from {1,2,3} to {1,2,3,4} with R = {(1,1),R is the relation from {1,2,3} to {1,2,3,4} with R = {(1,1), (1,4), (2,3), (3,1), (3,4)} and S is the relation from(1,4), (2,3), (3,1), (3,4)} and S is the relation from {1,2,3,4} to {0,1,2} with S = {(1,0), (2,0), (3,1), (3,2),{1,2,3,4} to {0,1,2} with S = {(1,0), (2,0), (3,1), (3,2), (4,1)}?(4,1)}? Solution:Solution: SS °° R is constructed using all ordered pairsR is constructed using all ordered pairs in R and ordered pairs in S, where the second elementin R and ordered pairs in S, where the second element of the ordered in R agrees with the first element ofof the ordered in R agrees with the first element of the ordered pair in S.the ordered pair in S. For example, the ordered pairs (2,3) in R and (3,1) in SFor example, the ordered pairs (2,3) in R and (3,1) in S produce the ordered pair (2,1) in Sproduce the ordered pair (2,1) in S °° R. Computing allR. Computing all the ordered pairs in the composite, we findthe ordered pairs in the composite, we find SS °° R = ((1,0), (1,1), (2,1), (2,2), (3,0), (3,1)}R = ((1,0), (1,1), (2,1), (2,2), (3,0), (3,1)}
56. 56. 56 Combining RelationsCombining Relations Definition:Definition: Let R be a relation on the set A.Let R be a relation on the set A. The powers RThe powers Rnn , n = 1, 2, 3, …, are defined, n = 1, 2, 3, …, are defined inductively byinductively by RR11 = R= R RRn+1n+1 = R= Rnn °° RR In other words:In other words: RRnn = R= R°° RR°° …… °° R (n times the letter R)R (n times the letter R)
57. 57. ExampleExample LetLet RR == {(1, 1), (2, 1), (3, 2), (4, 3)}.{(1, 1), (2, 1), (3, 2), (4, 3)}. Find the powersFind the powers RRnn ,, nn=2, 3, 4,….=2, 3, 4,…. Solution: R2 = R R = {(1, 1), (2, 1), (3, 1), (4, 2)}. R3 = R2 R = {(1, 1), (2, 1), (3, 1), (4, 1)}. Therefore Rn = R3 for n=4, 5, ….
58. 58. Combining RelationsCombining Relations Theorem:Theorem: The relation R on a set A is transitive ifThe relation R on a set A is transitive if and only if Rand only if Rnn ⊆⊆ R for all positive integers n.R for all positive integers n. Remember the definition of transitivity:Remember the definition of transitivity: Definition:Definition: A relation R on a set A is calledA relation R on a set A is called transitive if whenever (a, b)transitive if whenever (a, b)∈∈R and (b, c)R and (b, c)∈∈R, thenR, then (a, c)(a, c)∈∈R for a, b, cR for a, b, c∈∈A.A. The composite of R with itself contains exactlyThe composite of R with itself contains exactly these pairs (a, c).these pairs (a, c). Therefore, for a transitive relation R, RTherefore, for a transitive relation R, R°° R does notR does not contain any pairs that are not in R, so Rcontain any pairs that are not in R, so R°° RR ⊆⊆ R.R. Since RSince R°° R does not introduce any pairs that are notR does not introduce any pairs that are not already in R, it must also be true that (Ralready in R, it must also be true that (R°° R)R)°° RR ⊆⊆ R,R, and so on, so that Rand so on, so that Rnn ⊆⊆ R.R.
59. 59. Exercise QuestionExercise Question Exercise 9.1 page No. 581Exercise 9.1 page No. 581 Question No:Question No: 1 , 2 , 3 , 4, 5 , 6 , 7 , 10 , 11 ,1 , 2 , 3 , 4, 5 , 6 , 7 , 10 , 11 , 12 , 13 , 14 , 15 , 16, 26 , 27 , 28 , 34-37 ,12 , 13 , 14 , 15 , 16, 26 , 27 , 28 , 34-37 , 40 , 41 , 42 ,43 , 44 , 47 , 48 , 50 , 56 ,40 , 41 , 42 ,43 , 44 , 47 , 48 , 50 , 56 , 5858 Example in These Slides and also FromExample in These Slides and also From Book Both Include in your exam.Book Both Include in your exam.
60. 60. n-ary Relationsn-ary Relations In order to study an interesting application ofIn order to study an interesting application of relations, namelyrelations, namely databasesdatabases, we first need to, we first need to generalize the concept of binary relations togeneralize the concept of binary relations to n-aryn-ary relationsrelations.. Definition:Definition: Let ALet A11, A, A22, …, A, …, Ann be sets. Anbe sets. An n-aryn-ary relationrelation on these sets is a subset of Aon these sets is a subset of A11××AA22××……××AAnn.. The sets AThe sets A11, A, A22, …, A, …, Ann are called theare called the domainsdomains of theof the relation, and n is called itsrelation, and n is called its degreedegree..
61. 61. ExampleExample Let R be the relation on N * N * N consistingLet R be the relation on N * N * N consisting of triples (a, b, c) where a, b, and c areof triples (a, b, c) where a, b, and c are integers with a<b<c. Then (1,2,3)integers with a<b<c. Then (1,2,3) ∈∈ R, butR, but (2,4,3)(2,4,3) ∉∉ R. The degree of this relation is 3.R. The degree of this relation is 3. Its domains are equal to the set of integers.Its domains are equal to the set of integers.
62. 62. nn-ary Relations-ary Relations A binary relation involves 2 sets and can beA binary relation involves 2 sets and can be described by a set ofdescribed by a set of pairspairs A ternary relation involves 3 sets and can beA ternary relation involves 3 sets and can be described by a set ofdescribed by a set of triplestriples …… An n-ary relation involves n sets and can beAn n-ary relation involves n sets and can be described by a set ofdescribed by a set of n-tuplesn-tuples
63. 63. Databases and RelationsDatabases and Relations Let us take a look at a type of databaseLet us take a look at a type of database representation that is based on relations, namelyrepresentation that is based on relations, namely thethe relational data model.relational data model. A database consists of n-tuples calledA database consists of n-tuples called recordsrecords,, which are made up ofwhich are made up of fieldsfields.. These fields are theThese fields are the entriesentries of the n-tuples.of the n-tuples. The relational data model represents a databaseThe relational data model represents a database as an n-ary relation, that is, a set of records.as an n-ary relation, that is, a set of records.
64. 64. Databases and RelationsDatabases and Relations – Relational database modelRelational database model has beenhas been developed for information processingdeveloped for information processing – A database consists of records, whichA database consists of records, which are n-tuples made up of fieldsare n-tuples made up of fields – The fields contains information such as:The fields contains information such as: • NameName • Student #Student # • MajorMajor • Grade point average of the studentGrade point average of the student
65. 65. Databases and RelationsDatabases and Relations Example:Example: Consider a database of students, whoseConsider a database of students, whose records are represented as 4-tuples with the fieldsrecords are represented as 4-tuples with the fields Student NameStudent Name,, ID NumberID Number,, MajorMajor, and, and GPAGPA:: R = {(Ackermann, 231455, CS, 3.88),R = {(Ackermann, 231455, CS, 3.88), (Adams, 888323, Physics, 3.45),(Adams, 888323, Physics, 3.45), (Chou, 102147, CS, 3.79),(Chou, 102147, CS, 3.79), (Goodfriend, 453876, Math, 3.45),(Goodfriend, 453876, Math, 3.45), (Rao, 678543, Math, 3.90),(Rao, 678543, Math, 3.90), (Stevens, 786576, Psych, 2.99)}(Stevens, 786576, Psych, 2.99)} Relations that represent databases are also calledRelations that represent databases are also called tablestables, since they are often displayed as tables., since they are often displayed as tables.
66. 66. Databases and RelationsDatabases and Relations A domain of an n-ary relation is called aA domain of an n-ary relation is called a primaryprimary keykey if the n-tuples are uniquely determined byif the n-tuples are uniquely determined by their values from this domain.their values from this domain. This means that no two records have the sameThis means that no two records have the same value from the same primary key.value from the same primary key. In our example, which of the fieldsIn our example, which of the fields Student NameStudent Name,, ID NumberID Number,, MajorMajor, and, and GPAGPA are primary keys?are primary keys? Student NameStudent Name andand ID NumberID Number are primary keys,are primary keys, because no two students have identical values inbecause no two students have identical values in these fields.these fields. In a real student database, onlyIn a real student database, only ID NumberID Number wouldwould be a primary key.be a primary key.
68. 68. Selection operator sSelection operator sCC
69. 69. Databases and RelationsDatabases and Relations We can apply a variety ofWe can apply a variety of operationsoperations on n-aryon n-ary relations to form new relations.relations to form new relations. Definition:Definition: TheThe projectionprojection PPii11, i, i22, …, i, …, imm maps the n-tuplemaps the n-tuple (a(a11, a, a22, …, a, …, ann) to the m-tuple (a) to the m-tuple (aii11 , a, aii22 , …, a, …, aiimm ), where m), where m ≤≤ n.n. In other words, a projection PIn other words, a projection Pii11, i, i22, …, i, …, imm keeps the mkeeps the m components acomponents aii11 , a, aii22 , …, a, …, aiimm of an n-tuple and deletes itsof an n-tuple and deletes its (n – m) other components.(n – m) other components. Example:Example: What is the result when we apply theWhat is the result when we apply the projection Pprojection P2,42,4 to the student record (Stevens,to the student record (Stevens, 786576, Psych, 2.99) ?786576, Psych, 2.99) ? Solution:Solution: It is the pair (786576, 2.99).It is the pair (786576, 2.99).
70. 70. ExampleExample Students Names ID # Major GPA Smith Stevens Rao Adams Lee 3214 1412 6633 1320 1030 Mathematics Computer Science Physics Biology Computer Science 3.9 4.0 3.5 3.0 3.7 TABLE A: Students
71. 71. SolutionSolution What relation results when the projection PWhat relation results when the projection P1,41,4 isis applied to the relation in Table A?applied to the relation in Table A? Solution:Solution: When the projection PWhen the projection P1,41,4 is used, theis used, the second and third columns of the table are deleted,second and third columns of the table are deleted, and pairs representing student names and GPA areand pairs representing student names and GPA are obtained. Table B displays the results of thisobtained. Table B displays the results of this projection.projection. Students Names GPA Smith Stevens Rao Adams Lee 3.9 4.0 3.5 3.0 3.7 TABLE B: GPAs
72. 72. 73 Databases and RelationsDatabases and Relations We can use theWe can use the joinjoin operation to combine twooperation to combine two tables into one if they share some identical fields.tables into one if they share some identical fields. Definition:Definition: Let R be a relation of degree m and S aLet R be a relation of degree m and S a relation of degree n. Therelation of degree n. The joinjoin JJpp(R, S), where p(R, S), where p ≤≤ mm and pand p ≤≤ n, is a relation of degree m + n – p thatn, is a relation of degree m + n – p that consists of all (m + n – p)-tuplesconsists of all (m + n – p)-tuples (a(a11, a, a22, …, a, …, am-pm-p, c, c11, c, c22, …, c, …, cpp, b, b11, b, b22, …, b, …, bn-pn-p),), where the m-tuple (awhere the m-tuple (a11, a, a22, …, a, …, am-pm-p, c, c11, c, c22, …, c, …, cpp) belongs) belongs to R and the n-tuple (cto R and the n-tuple (c11, c, c22, …, c, …, cpp, b, b11, b, b22, …, b, …, bn-pn-p)) belongs to S.belongs to S.
73. 73. 74 Databases and RelationsDatabases and Relations In other words, to generate Jp(R, S), we have toIn other words, to generate Jp(R, S), we have to find all the elements in R whose p last componentsfind all the elements in R whose p last components match the p first components of an element in S.match the p first components of an element in S. The new relation contains exactly these matches,The new relation contains exactly these matches, which are combined to tuples that contain eachwhich are combined to tuples that contain each matching field only once.matching field only once.
74. 74. Databases and RelationsDatabases and Relations Example:Example: What is JWhat is J11(Y, R), where Y contains the(Y, R), where Y contains the fieldsfields Student NameStudent Name andand Year of BirthYear of Birth,, Y = {(1978, Ackermann),Y = {(1978, Ackermann), (1972, Adams),(1972, Adams), (1917, Chou),(1917, Chou), (1984, Goodfriend),(1984, Goodfriend), (1982, Rao),(1982, Rao), (1970, Stevens)},(1970, Stevens)}, and R contains the student records as definedand R contains the student records as defined before ?before ?
75. 75. 76 Databases and RelationsDatabases and Relations Solution:Solution: The resulting relation is:The resulting relation is: {(1978, Ackermann, 231455, CS, 3.88),{(1978, Ackermann, 231455, CS, 3.88), (1972, Adams, 888323, Physics, 3.45),(1972, Adams, 888323, Physics, 3.45), (1917, Chou, 102147, CS, 3.79),(1917, Chou, 102147, CS, 3.79), (1984, Goodfriend, 453876, Math, 3.45),(1984, Goodfriend, 453876, Math, 3.45), (1982, Rao, 678543, Math, 3.90),(1982, Rao, 678543, Math, 3.90), (1970, Stevens, 786576, Psych, 2.99)}(1970, Stevens, 786576, Psych, 2.99)} Since Y has two fields and R has four, the relationSince Y has two fields and R has four, the relation JJ11(Y, R) has 2 + 4 – 1 = 5 fields.(Y, R) has 2 + 4 – 1 = 5 fields.
76. 76. Another ExampleAnother Example Example:Example: What relation results whenWhat relation results when the operator Jthe operator J22 is used to combine theis used to combine the relation displayed in tables C and D?relation displayed in tables C and D?
77. 77. Professor Dpt Course # Cruz Cruz Farber Farber Grammar Grammar Rosen Rosen Zoology Zoology Psychology Psychology Physics Physics Computer Science Mathematics 335 412 501 617 544 551 518 575 Dpt Course # Room Time Computer Science Mathematics Mathematics Physics Psychology Psychology Zoology Zoology 518 575 611 544 501 617 335 412 N521 N502 N521 B505 A100 A110 A100 A100 2:00 PM 3:00 PM 4:00 PM 4:00 PM 3:00 PM 11:00 AM 9:00 AM 8:00 AM TABLE C: Teaching Assignments TABLE D: Class Schedule
78. 78. Solution:Solution: The join JThe join J22 produces the relationproduces the relation shown in Table Eshown in Table E Professor Dpt Course # Room Time Cruz Cruz Farber Farber Grammer Rosen Rosen Zoology Zoology Psychology Psychology Physics Computer Science Mathematics 335 412 501 617 544 518 575 A100 A100 A100 A110 B505 N521 N502 9:00 AM 8:00 AM 3:00 PM 11:00 AM 4:00 PM 2:00 PM 3:00 PM Table E: Teaching Schedule
79. 79. 80 Representing RelationsRepresenting Relations We already know different ways of representingWe already know different ways of representing relations. We will now take a closer look at tworelations. We will now take a closer look at two ways of representation:ways of representation: Zero-one matricesZero-one matrices andand directed graphsdirected graphs.. If R is a relation from A = {aIf R is a relation from A = {a11, a, a22, …, a, …, amm} to B =} to B = {b{b11, b, b22, …, b, …, bnn}, then R can be represented by the}, then R can be represented by the zero-one matrix Mzero-one matrix MRR = [m= [mijij] with] with mmijij = 1, if (a= 1, if (aii, b, bjj))∈∈R, andR, and mmijij = 0, if (a= 0, if (aii, b, bjj))∉∉R.R. Note that for creating this matrix we first need toNote that for creating this matrix we first need to list the elements in A and B in alist the elements in A and B in a particular, butparticular, but arbitrary orderarbitrary order..
80. 80. 81 Representing RelationsRepresenting Relations Example:Example: How can we represent the relationHow can we represent the relation R = {(2, 1), (3, 1), (3, 2)} as a zero-one matrix?R = {(2, 1), (3, 1), (3, 2)} as a zero-one matrix? Solution:Solution: The matrix MThe matrix MRR is given byis given by           = 11 01 00 RM
81. 81. 82 Representing RelationsRepresenting Relations What do we know about the matrices representingWhat do we know about the matrices representing aa relation on a setrelation on a set (a relation from A to A) ?(a relation from A to A) ? They areThey are squaresquare matrices.matrices. What do we know about matrices representingWhat do we know about matrices representing reflexivereflexive relations?relations? All the elements on theAll the elements on the diagonaldiagonal of such matricesof such matrices MMrefref must bemust be 1s1s..                     = 1 . . . 1 1 refM
82. 82. 83 Representing RelationsRepresenting Relations What do we know about the matrices representingWhat do we know about the matrices representing symmetric relationssymmetric relations?? These matrices are symmetric, that is, MThese matrices are symmetric, that is, MRR = (M= (MRR))tt ..             = 1101 1001 0010 1101 RM symmetric matrix,symmetric matrix, symmetric relation.symmetric relation.             = 0011 0011 0011 0011 RM non-symmetric matrix,non-symmetric matrix, non-symmetric relation.non-symmetric relation.
83. 83. 84 Representing RelationsRepresenting Relations The Boolean operationsThe Boolean operations joinjoin andand meetmeet (you(you remember?)remember?) can be used to determine the matricescan be used to determine the matrices representing therepresenting the unionunion and theand the intersectionintersection of twoof two relations, respectively.relations, respectively. To obtain theTo obtain the joinjoin of two zero-one matrices, weof two zero-one matrices, we apply the Boolean “or” function to all correspondingapply the Boolean “or” function to all corresponding elements in the matrices.elements in the matrices. To obtain theTo obtain the meetmeet of two zero-one matrices, weof two zero-one matrices, we apply the Boolean “and” function to all correspondingapply the Boolean “and” function to all corresponding elements in the matrices.elements in the matrices.
84. 84. 85 Representing RelationsRepresenting Relations Example:Example: Let the relations R and S be representedLet the relations R and S be represented by the matricesby the matrices           =∨=∪ 011 111 101 SRSR MMM           = 001 110 101 SM What are the matrices representing RS and RS?What are the matrices representing RS and RS? Solution:Solution: These matrices are given byThese matrices are given by           =∧=∩ 000 000 101 SRSR MMM           = 010 001 101 RM
85. 85. 86 Representing Relations Using MatricesRepresenting Relations Using Matrices Example:Example: How can we represent the relationHow can we represent the relation R = {(2, 1), (3, 1), (3, 2)} as a zero-one matrix?R = {(2, 1), (3, 1), (3, 2)} as a zero-one matrix? Solution:Solution: The matrix MThe matrix MRR is given byis given by           = 11 01 00 RM
86. 86. 87 Representing Relations Using MatricesRepresenting Relations Using Matrices Example:Example: Let the relations R and S be representedLet the relations R and S be represented by the matricesby the matrices           =∨=∪ 011 111 101 SRSR MMM           = 001 110 101 SM What are the matrices representing RS and RS?What are the matrices representing RS and RS? Solution:Solution: These matrices are given byThese matrices are given by           =∧=∩ 000 000 101 SRSR MMM           = 010 001 101 RM
87. 87. 88 Representing Relations Using MatricesRepresenting Relations Using Matrices Do you remember theDo you remember the Boolean productBoolean product of twoof two zero-one matrices?zero-one matrices? Let A = [aLet A = [aijij] be an mk zero-one matrix and] be an mk zero-one matrix and B = [bB = [bijij] be a kn zero-one matrix.] be a kn zero-one matrix. Then theThen the Boolean productBoolean product of A and B, denoted byof A and B, denoted by AB, is the mn matrix with (i, j)th entry [cAB, is the mn matrix with (i, j)th entry [cijij],], wherewhere ccijij = (a= (ai1i1  b b1j1j)  (a)  (ai2i2  b b2i2i)  …  (a)  …  (aikik  b bkjkj).). ccijij = 1 if and only if at least one of the terms= 1 if and only if at least one of the terms (a(ainin  b bnjnj) = 1 for some n; otherwise c) = 1 for some n; otherwise cijij = 0.= 0.
88. 88. 89 Representing Relations Using MatricesRepresenting Relations Using Matrices Let us now assume that the zero-one matricesLet us now assume that the zero-one matrices MMAA = [a= [aijij], M], MBB = [b= [bijij] and M] and MCC = [c= [cijij] represent] represent relations A, B, and C, respectively.relations A, B, and C, respectively. Remember:Remember: For MFor MCC = M= MAAMMBB we have:we have: ccijij = 1 if and only if at least one of the terms= 1 if and only if at least one of the terms (a(ainin  b bnjnj) = 1 for some n; otherwise c) = 1 for some n; otherwise cijij = 0.= 0. In terms of theIn terms of the relationsrelations, this means that C, this means that C contains a pair (xcontains a pair (xii, z, zjj) if and only if there is an) if and only if there is an element yelement ynn such that (xsuch that (xii, y, ynn) is in relation A and) is in relation A and (y(ynn, z, zjj) is in relation B.) is in relation B. Therefore, C = BTherefore, C = BA (A (compositecomposite of A and B).of A and B).
89. 89. 90 Representing Relations Using MatricesRepresenting Relations Using Matrices This gives us the following rule:This gives us the following rule: MMBBAA = M= MAAMMBB In other words, the matrix representing theIn other words, the matrix representing the compositecomposite of relations A and B is theof relations A and B is the BooleanBoolean productproduct of the matrices representing A and B.of the matrices representing A and B. Analogously, we can find matrices representing theAnalogously, we can find matrices representing the powers of relationspowers of relations:: MMRRnn = M= MRR [n][n] (n-th(n-th Boolean powerBoolean power).).
90. 90. 91 Representing Relations Using MatricesRepresenting Relations Using Matrices Example:Example: Find the matrix representing RFind the matrix representing R22 , where, where the matrix representing R is given bythe matrix representing R is given by           = 001 110 010 RM Solution:Solution: The matrix for RThe matrix for R22 is given byis given by           == 010 111 110 ]2[ 2 RR MM
91. 91. 92 Representing Relations Using DigraphsRepresenting Relations Using Digraphs Definition:Definition: AA directed graphdirected graph, or, or digraphdigraph, consists, consists of a set V ofof a set V of verticesvertices (or(or nodesnodes) together with a) together with a set E of ordered pairs of elements of V calledset E of ordered pairs of elements of V called edgesedges (or(or arcsarcs).). The vertex a is called theThe vertex a is called the initial vertexinitial vertex of theof the edge (a, b), and the vertex b is called theedge (a, b), and the vertex b is called the terminalterminal vertexvertex of this edge.of this edge. We can use arrows to display graphs.We can use arrows to display graphs.
92. 92. 93 Representing Relations Using DigraphsRepresenting Relations Using Digraphs Example:Example: Display the digraph with V = {a, b, c, d},Display the digraph with V = {a, b, c, d}, E = {(a, b), (a, d), (b, b), (b, d), (c, a), (c, b), (d, b)}.E = {(a, b), (a, d), (b, b), (b, d), (c, a), (c, b), (d, b)}. aa bb ccdd An edge of the form (b, b) is called aAn edge of the form (b, b) is called a loop.loop.
93. 93. 94 Representing Relations Using DigraphsRepresenting Relations Using Digraphs Obviously, we can represent any relation R on a setObviously, we can represent any relation R on a set A by the digraph with A as its vertices and all pairsA by the digraph with A as its vertices and all pairs (a, b)(a, b)∈∈R as its edges.R as its edges. Vice versa, any digraph with vertices V and edges EVice versa, any digraph with vertices V and edges E can be represented by a relation on V containing allcan be represented by a relation on V containing all the pairs in E.the pairs in E. ThisThis one-to-one correspondenceone-to-one correspondence betweenbetween relations and digraphs means that any statementrelations and digraphs means that any statement about relations also applies to digraphs, and viceabout relations also applies to digraphs, and vice versa.versa.
94. 94. 95 Equivalence RelationsEquivalence Relations Equivalence relationsEquivalence relations are used to relate objectsare used to relate objects that are similar in some way.that are similar in some way. Definition:Definition: A relation on a set A is called anA relation on a set A is called an equivalence relation if it is reflexive, symmetric,equivalence relation if it is reflexive, symmetric, and transitive.and transitive. Two elements that are related by an equivalenceTwo elements that are related by an equivalence relation R are calledrelation R are called equivalentequivalent..
95. 95. 96 Equivalence RelationsEquivalence Relations Since R isSince R is symmetricsymmetric, a is equivalent to b whenever, a is equivalent to b whenever b is equivalent to a.b is equivalent to a. Since R isSince R is reflexivereflexive, every element is equivalent to, every element is equivalent to itself.itself. Since R isSince R is transitivetransitive, if a and b are equivalent and b, if a and b are equivalent and b and c are equivalent, then a and c are equivalent.and c are equivalent, then a and c are equivalent. Obviously, these three properties are necessaryObviously, these three properties are necessary for a reasonable definition of equivalence.for a reasonable definition of equivalence.
96. 96. 97 Equivalence RelationsEquivalence Relations Example:Example: Suppose that R is the relation on the setSuppose that R is the relation on the set of strings that consist of English letters such thatof strings that consist of English letters such that aRb if and only if l(a) = l(b), where l(x) is the lengthaRb if and only if l(a) = l(b), where l(x) is the length of the string x. Is R an equivalence relation?of the string x. Is R an equivalence relation? Solution:Solution: • R is reflexive, because l(a) = l(a) and thereforeR is reflexive, because l(a) = l(a) and therefore aRa for any string a.aRa for any string a. • R is symmetric, because if l(a) = l(b) then l(b) =R is symmetric, because if l(a) = l(b) then l(b) = l(a), so if aRb then bRa.l(a), so if aRb then bRa. • R is transitive, because if l(a) = l(b) and l(b) = l(c),R is transitive, because if l(a) = l(b) and l(b) = l(c), then l(a) = l(c), so aRb and bRc implies aRc.then l(a) = l(c), so aRb and bRc implies aRc. R is an equivalence relation.R is an equivalence relation.
97. 97. 98 Equivalence ClassesEquivalence Classes Definition:Definition: Let R be an equivalence relation on aLet R be an equivalence relation on a set A. The set of all elements that are related toset A. The set of all elements that are related to an element a of A is called thean element a of A is called the equivalence classequivalence class of a.of a. The equivalence class of a with respect to R isThe equivalence class of a with respect to R is denoted bydenoted by [a][a]RR.. When only one relation is under consideration, weWhen only one relation is under consideration, we will delete the subscript R and writewill delete the subscript R and write [a][a] for thisfor this equivalence class.equivalence class. If bIf b∈∈[a][a]RR, b is called a, b is called a representativerepresentative of thisof this equivalence class.equivalence class.
98. 98. 99 Equivalence ClassesEquivalence Classes Example:Example: In the previous example (strings ofIn the previous example (strings of identical length), what is the equivalence class ofidentical length), what is the equivalence class of the word mouse, denoted by [mouse] ?the word mouse, denoted by [mouse] ? Solution:Solution: [mouse] is the set of all English words[mouse] is the set of all English words containing five letters.containing five letters. For example, ‘horse’ would be a representative ofFor example, ‘horse’ would be a representative of this equivalence class.this equivalence class.
99. 99. 100 Equivalence ClassesEquivalence Classes Theorem:Theorem: Let R be an equivalence relation on a setLet R be an equivalence relation on a set A. The following statements are equivalent:A. The following statements are equivalent: • aRbaRb • [a] = [b][a] = [b] • [a][a] ∩∩ [b][b] ≠≠ ∅∅ Definition:Definition: AA partitionpartition of a set S is a collection ofof a set S is a collection of disjoint nonempty subsets of S that have S as theirdisjoint nonempty subsets of S that have S as their union. In other words, the collection of subsets Aunion. In other words, the collection of subsets Aii,, ii∈∈I, forms a partition of S if and only ifI, forms a partition of S if and only if (i) A(i) Aii ≠≠ ∅∅ for ifor i∈∈II • AAii ∩∩ AAjj == ∅∅, if i, if i ≠≠ jj • ∪∪ii∈∈II AAii = S= S
100. 100. 101 Equivalence ClassesEquivalence Classes Examples:Examples: Let S be the set {u, m, b, r, o, c, k, s}.Let S be the set {u, m, b, r, o, c, k, s}. Do the following collections of sets partition S ?Do the following collections of sets partition S ? {{m, o, c, k}, {r, u, b, s}}{{m, o, c, k}, {r, u, b, s}} yes.yes. {{c, o, m, b}, {u, s}, {r}}{{c, o, m, b}, {u, s}, {r}} no (k is missing).no (k is missing). {{b, r, o, c, k}, {m, u, s, t}}{{b, r, o, c, k}, {m, u, s, t}} no (t is not in S).no (t is not in S). {{u, m, b, r, o, c, k, s}}{{u, m, b, r, o, c, k, s}} yes.yes. {{b, o, o, k}, {r, u, m}, {c, s}}{{b, o, o, k}, {r, u, m}, {c, s}} yes ({b,o,o,k} = {b,o,k}).yes ({b,o,o,k} = {b,o,k}). {{u, m, b}, {r, o, c, k, s}, }{{u, m, b}, {r, o, c, k, s}, } no ( not allowed).no ( not allowed).
101. 101. 102 Equivalence ClassesEquivalence Classes Theorem:Theorem: Let R be an equivalence relation on aLet R be an equivalence relation on a set S. Then theset S. Then the equivalence classesequivalence classes of R form aof R form a partitionpartition of S. Conversely, given a partitionof S. Conversely, given a partition {A{Aii | i| i∈∈I} of the set S, there is an equivalenceI} of the set S, there is an equivalence relation R that has the sets Arelation R that has the sets Aii, i, i∈∈I, as itsI, as its equivalence classes.equivalence classes.
102. 102. 103 Equivalence ClassesEquivalence Classes Example:Example: Let us assume that Frank, Suzanne andLet us assume that Frank, Suzanne and George live in Boston, Stephanie and Max live inGeorge live in Boston, Stephanie and Max live in Lübeck, and Jennifer lives in Sydney.Lübeck, and Jennifer lives in Sydney. Let R be theLet R be the equivalence relationequivalence relation {(a, b) | a and b{(a, b) | a and b live in the same city} on the set P = {Frank,live in the same city} on the set P = {Frank, Suzanne, George, Stephanie, Max, Jennifer}.Suzanne, George, Stephanie, Max, Jennifer}. Then R = {(Frank, Frank), (Frank, Suzanne),Then R = {(Frank, Frank), (Frank, Suzanne), (Frank, George), (Suzanne, Frank), (Suzanne,(Frank, George), (Suzanne, Frank), (Suzanne, Suzanne), (Suzanne, George), (George, Frank),Suzanne), (Suzanne, George), (George, Frank), (George, Suzanne), (George, George), (Stephanie,(George, Suzanne), (George, George), (Stephanie, Stephanie), (Stephanie, Max), (Max, Stephanie),Stephanie), (Stephanie, Max), (Max, Stephanie), (Max, Max), (Jennifer, Jennifer)}.(Max, Max), (Jennifer, Jennifer)}.
103. 103. 104 Equivalence ClassesEquivalence Classes Then theThen the equivalence classesequivalence classes of R are:of R are: {{Frank, Suzanne, George}, {Stephanie, Max},{{Frank, Suzanne, George}, {Stephanie, Max}, {Jennifer}}.{Jennifer}}. This is aThis is a partitionpartition of P.of P. The equivalence classes of any equivalence relationThe equivalence classes of any equivalence relation R defined on a set S constitute a partition of S,R defined on a set S constitute a partition of S, because every element in S is assigned tobecause every element in S is assigned to exactlyexactly oneone of the equivalence classes.of the equivalence classes.
104. 104. 105 Equivalence ClassesEquivalence Classes Another example:Another example: Let R be the relationLet R be the relation {(a, b) | a{(a, b) | a ≡≡ b (mod 3)} on the set of integers.b (mod 3)} on the set of integers. Is R an equivalence relation?Is R an equivalence relation? Yes, R is reflexive, symmetric, and transitive.Yes, R is reflexive, symmetric, and transitive. What are the equivalence classes of R ?What are the equivalence classes of R ? {{…, -6, -3, 0, 3, 6, …},{{…, -6, -3, 0, 3, 6, …}, {…, -5, -2, 1, 4, 7, …},{…, -5, -2, 1, 4, 7, …}, {…, -4, -1, 2, 5, 8, …}}{…, -4, -1, 2, 5, 8, …}}
105. 105. ThanksThanks 
106. 106. Any QuestionAny Question ??

Jul. 5, 2021
• #### shakilaAbaidullah

Jun. 19, 2021
• #### JohnPatrickSanchez1

Apr. 27, 2021
• #### PrinceOB1

Mar. 31, 2021
• #### Avdhutchavan2

Mar. 29, 2021
• #### DHEERAJMINOCHA1

Mar. 29, 2021
• #### AbdulWaheed415

Feb. 15, 2021

Feb. 9, 2021
• #### eruditeandeunoias

Jan. 6, 2021

Nov. 19, 2020
• #### AhmedIsmail43

Nov. 18, 2020
• #### RennanAmoguis

Nov. 18, 2020
• #### EnasElgbbas

Nov. 17, 2020

Nov. 10, 2020
• #### WikiAlharki

Oct. 23, 2020

Oct. 5, 2020
• #### VamsiKrishna1705

Sep. 27, 2020
• #### AbuRayhanAbdullahKha

Sep. 10, 2020
• #### shashikalahebbar

Aug. 30, 2020
• #### PranjalRastogi12

Aug. 26, 2020

What is a Relation Representing relations Functions as Relations Relations on a Set Relation properties Combining Relations Databases and Relations Representing Relations Using Matrices Equivalence Classes

Total views

35,156

On Slideshare

0

From embeds

0

Number of embeds

3

0

Shares

0