15
08/28/22 1 §7.3 Representing Relations Longin Jan Latecki Slides adapted from Kees van Deemter who Slides adapted from Kees van Deemter who adopted them from Michael P. Frank’s adopted them from Michael P. Frank’s Course Based on the Text Course Based on the Text Discrete Mathematics & Its Applications Discrete Mathematics & Its Applications (5 (5 th th Edition) Edition) by Kenneth H. Rosen by Kenneth H. Rosen

§7.3 Representing Relations Longin Jan Latecki

Embed Size (px)

DESCRIPTION

§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. §7.3: Representing Relations. - PowerPoint PPT Presentation

Citation preview

Page 1: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 1

§7.3 Representing Relations Longin Jan Latecki

Slides adapted from Kees van Deemter who adopted them Slides adapted from Kees van Deemter who adopted them from Michael P. Frank’s from Michael P. Frank’s Course Based on the TextCourse Based on the Text

Discrete Mathematics & Its ApplicationsDiscrete Mathematics & Its Applications (5(5thth Edition) Edition)

by Kenneth H. Rosenby Kenneth H. Rosen

Page 2: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 2

§7.3: Representing Relations

• Some ways to represent Some ways to represent nn-ary relations:-ary relations:– With a list of tuples.With a list of tuples.– With a function from the domain to With a function from the domain to {{TT,,FF}}..

• Special ways to represent binary relations:Special ways to represent binary relations:– With a zero-one matrix.With a zero-one matrix.– With a directed graph.With a directed graph.

Page 3: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 3

• Why bother with alternative Why bother with alternative representations? Is one not enough?representations? Is one not enough?

• One reason: some things are easier using One reason: some things are easier using one representation, some things are easier one representation, some things are easier using anotherusing another

It’s often worth playing around with different representations!It’s often worth playing around with different representations!

Page 4: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 4

Connection or (Zero-One) Matrices

Let R be a relation from

A = {a1, a2, . . . , am} to B = {b1, b2, . . . , 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.

Page 5: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 5

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

Page 6: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 6

• Special case 1-0 matrices for a relation Special case 1-0 matrices for a relation on A (that is, on A (that is, RR::AA××AA))

• Convention: rows and columns list elements Convention: rows and columns list elements in the same orderin the same order

Page 7: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 7

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.

Page 8: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 8

Zero-One Reflexive, Symmetric

• Recall:Recall: Reflexive Reflexive,, irreflexive irreflexive,,ssymmetric, and asymmetric ymmetric, and asymmetric relations.relations.– 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.

0

0

101

0

0

01

1

0

0

0

0

1

1

1

1

Reflexive:only 1’s on diagonal

Irreflexive:only 0’s on diagonal

Symmetric:all identical

across diagonal

Asymmetric:all 1’s are across

from 0’s

any-thing

any-thing

any-thing

any-thing

anything

anything

Page 9: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 9

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 (arcs)edges (arcs). .

Visually represented using dots for nodes, and arrows for Visually represented using dots for nodes, and arrows for edges. A relation edges. A relation RR::AA××BB can be represented as a graph can be 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)

Page 10: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 10

Digraph Reflexive, SymmetricIt is easy to recognize the reflexive/irreflexive/ It is 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

Asymmetric:

No link isbidirectional

These are not symmetric & not asymmetric These are non-reflexive & non-irreflexive

Page 11: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 11

Page 12: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 12

Obvious questions:

Given the connection matrix for two relations, how doesone find the connection matrix for

• The complement?• The symmetric difference?

Page 13: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 13

Page 14: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 14

Example

Page 15: §7.3  Representing Relations  Longin Jan Latecki

04/19/23 15

Question: