module #21 - relations 1 8.3 representing relations rosen 6 th ed., ch. 8
TRANSCRIPT
Module #21 - Relations
1
8.3 Representing Relations
Rosen 6Rosen 6thth ed., Ch. 8 ed., Ch. 8
Module #21 - Relations
2
§8.3: Representing Relations
• Some ways to represent Some ways to represent nn-ary relations:-ary relations:– With an explicit list or table of its tuples.With an explicit list or table of its tuples.– With a function from the domain to With a function from the domain to {{TT,,FF}}..
• Or with an algorithm for computing this function.Or with an algorithm for computing this function.
• Some special ways to represent binary Some special ways to represent binary relations:relations:– With a zero-one matrix.With a zero-one matrix.– With a directed graph.With a directed graph.
Module #21 - Relations
3
Using Zero-One Matrices• To represent a binary relation To represent a binary relation RR::AA××BB by an by an ||AA||×|×|BB||
0-1 matrix 0-1 matrix MMRR = [ = [mmijij]], let , let mmijij = 1 = 1 iff iff ((aaii,,bbjj))RR..• E.g.E.g., Suppose Joe likes Susan and Mary, Fred , Suppose Joe likes Susan and Mary, Fred
likes Mary, and Mark likes Sally.likes Mary, and Mark likes Sally.• Then the 0-1 matrix Then the 0-1 matrix
representationrepresentationof the relationof the relationLikes:BoysLikes:Boys×Girls×Girlsrelation is:relation is:
1 00
010
0 1 1
Mark
Fred
JoeSallyMarySusan
Module #21 - Relations
4
Properties of Relations
• Reflexivity: A relation R on AReflexivity: A relation R on A××A is A is reflexive if for all reflexive if for all aa ∈ ∈ A, (A, (a,aa,a) ) ∈ ∈ R.R.
• Symmetry: A relation R on ASymmetry: A relation R on A××A is A is symmetric if (symmetric if (x,yx,y) ) ∈∈ R implies ( R implies (y,xy,x) ) ∈∈ R. R.
• Anti-symmetry:Anti-symmetry: A relation on AA relation on A××A is anti-symmetric if (A is anti-symmetric if (a,ba,b) ) ∈∈ R and ( R and (b,ab,a) ) ∈∈ R implies a = b. R implies a = b.
Module #21 - Relations
5
Zero-One Reflexive, Symmetric
• Terms:Terms: Reflexive Reflexive, s, symmetric, and ymmetric, and antisymmetricantisymmetric..– These relation characteristics are very easy to These relation characteristics are very easy to
recognize by inspection of the zero-one matrix.recognize by inspection of the zero-one matrix.
1
1
1
1
1
1 0
0
0
1 0 1
0
0
Reflexive:all 1’s on diagonal
Symmetric:all identical
across diagonal
Antisymmetric:all 1’s are across
from 0’s
any-thing
any-thing
anything
anything
Module #21 - Relations
6
Using Directed Graphs
• A A directed graphdirected graph or or digraphdigraph GG=(=(VVGG,,EEGG)) is a set is a set VVGG of of
vertices (nodes)vertices (nodes) with a set with a set EEGGVVGG××VVGG of of edges edges
(arcs,links)(arcs,links). Visually represented using dots for nodes, . Visually represented using dots for nodes, and arrows for edges. Notice that a relation and arrows for edges. Notice that a relation RR::AA××BB can be can be represented as a graph represented as a graph GGRR=(=(VVGG==AABB, , EEGG==RR))..
1 00
010
0 1 1
Mark
Fred
JoeSallyMarySusan
Matrix representation MR: Graph rep. GR: Joe
Fred
Mark
Susan
Mary
Sally
Node set VG
(black dots)
Edge set EG
(blue arrows)
Module #21 - Relations
7
Digraph Reflexive, Symmetric
It is extremely easy to recognize the reflexive/irreflexive/ It is extremely easy to recognize the reflexive/irreflexive/ symmetric/antisymmetric properties by graph inspection.symmetric/antisymmetric properties by graph inspection.
Reflexive:Every node
has a self-loop
Irreflexive:No node
links to itself
Symmetric:Every link isbidirectional
Antisymmetric:
No link isbidirectional
These are asymmetric & non-antisymmetric These are non-reflexive & non-irreflexive
Module #21 - Relations
8
Properties of Relations
• Transitivity:Transitivity:
A relation on AA relation on A××A is transitive if (A is transitive if (a,ba,b) ) R R and (and (b,cb,c) ) R imply ( R imply (a,ca,c) ) R. R.
Graph??Graph??