7 3 Representing Relations Longin Jan Latecki Slides















- Slides: 15
§ 7. 3 Representing Relations Longin Jan Latecki Slides adapted from Kees van Deemter who adopted them from Michael P. Frank’s Course Based on the Text Discrete Mathematics & Its Applications (5 th Edition) by Kenneth H. Rosen 9/26/2021 1
§ 7. 3: Representing Relations • Some ways to represent n-ary relations: – With a list of tuples. – With a function from the domain to {T, F}. • Special ways to represent binary relations: – With a zero-one matrix. – With a directed graph. 9/26/2021 2
• Why bother with alternative representations? Is one not enough? • One reason: some things are easier using one representation, some things are easier using another It’s often worth playing around with different representations! 9/26/2021 3
Connection or (Zero-One) Matrices Let R be a relation from A = {a 1, a 2, . . . , am} to B = {b 1, b 2, . . . , bn}. Definition: An m x n connection matrix M for R is defined by Mij = 1 if <ai, bj> is in R, Mij = 0 otherwise. 9/26/2021 4
Using Zero-One Matrices • To represent a binary relation R: A×B by an |A|×|B| 0 -1 matrix MR = [mij], let mij = 1 iff (ai, bj) R. • E. g. , Suppose Joe likes Susan and Mary, Fred likes Mary, and Mark likes Sally. • Then the 0 -1 matrix representation of the relation Likes: Boys×Girls relation is: 9/26/2021 5
• Special case 1 -0 matrices for a relation on A (that is, R: A×A) • Convention: rows and columns list elements in the same order 9/26/2021 6
Theorem: Let R be a binary relation on a set A and let M be its connection matrix. Then • R is reflexive iff Mii = 1 for all i. • R is symmetric iff M is a symmetric matrix: M = MT • R is antisymetric if Mij = 0 or Mji = 0 for all i ≠ j. 9/26/2021 7
Zero-One Reflexive, Symmetric • Recall: Reflexive, irreflexive, symmetric, and asymmetric relations. – These relation characteristics are very easy to recognize by inspection of the zero-one matrix. g in h yt an an anything Reflexive: Irreflexive: only 1’s on diagonal only 0’s on diagonal 9/26/2021 Symmetric: all identical across diagonal Asymmetric: all 1’s are across from 0’s 8
Using Directed Graphs • A directed graph or digraph G=(VG, EG) is a set VG of vertices (nodes) with a set EG VG×VG of edges (arcs). Visually represented using dots for nodes, and arrows for edges. A relation R: A×B can be represented as a graph GR=(VG=A B, EG=R). Matrix representation MR: 9/26/2021 Graph rep. GR: Edge set EG (blue arrows) Joe Fred Mark Susan Mary Sally Node set VG (black dots) 9
Digraph Reflexive, Symmetric It is easy to recognize the reflexive/irreflexive/ symmetric/antisymmetric properties by graph inspection. Reflexive: Every node has a self-loop Irreflexive: No node links to itself These are not symmetric & not asymmetric 9/26/2021 Symmetric: Every link is bidirectional Asymmetric: No link is bidirectional These are non-reflexive & non-irreflexive 10
9/26/2021 11
Obvious questions: Given the connection matrix for two relations, how does one find the connection matrix for • The complement? • The symmetric difference? 9/26/2021 12
9/26/2021 13
Example 9/26/2021 14
Question: 9/26/2021 15