17 Representing Relations
-
Upload
majid-khan -
Category
Documents
-
view
215 -
download
0
Transcript of 17 Representing Relations
-
8/2/2019 17 Representing Relations
1/28
1
Representing Relations
Epp section ???
CS 202Aaron Bloomfield
-
8/2/2019 17 Representing Relations
2/28
2
In this slide set
Matrix review
Two ways to represent relations
Via matrices Via directed graphs
-
8/2/2019 17 Representing Relations
3/28
3
Matrix review
We will only be dealing with zero-one matrices Each element in the matrix is either a 0 or a 1
These matrices will be used for Booleanoperations 1 is true, 0 is false
0101
0101
0010
0001
-
8/2/2019 17 Representing Relations
4/28
4
Matrix transposition
Given a matrix M, the transposition ofM, denoted Mt, isthe matrix obtained by switching the columns and rows ofM
In a square matrix, the maindiagonal stays unchanged
=
654321M
=
16151413
1211109
8765
4321
M
=
63
52
41t
M
=
161284
151173
14106213951
tM
-
8/2/2019 17 Representing Relations
5/28
5
Matrix join
Ajoin of two matrices performs a Boolean
OR on each relative entry of the matrices
Matrices must be the same size
Denoted by the or symbol:
=
0111
1101
01100111
0011
1100
01100110
0101
0101
00100001
-
8/2/2019 17 Representing Relations
6/28
6
Matrix meet
A meet of two matrices performs a
Boolean AND on each relative entry of the
matrices
Matrices must be the same size
Denoted by the or symbol:
=
0001
0100
00100000
0011
1100
01100110
0101
0101
00100001
-
8/2/2019 17 Representing Relations
7/28
7
Matrix Boolean product
A Boolean product of two matrices is similar to matrix
multiplication
Instead of the sum of the products, its the conjunction (and) ofthe disjunctions (ors)
Denoted by the or symbol:
1,44,11,33,11,22,11,11,11,1 **** babababac +++=
1,44,11,33,11,22,11,11,11,1 babababac =
=
1110
1110
0110
0110
0011
1100
0110
0110
0101
0101
0010
0001
=
0
0011
1100
0110
0110
0101
0101
0010
0001
=
0011
1100
0110
0110
0101
0101
0010
0001
-
8/2/2019 17 Representing Relations
8/28
-
8/2/2019 17 Representing Relations
9/28
9
Relations using matrices
Consider the relation of who is enrolled in which
class
Let A = { Alice, Bob, Claire, Dan }
Let B = { CS101, CS201, CS202 } R = { (a,b) | person a is enrolled in course b }
=
110
000
110
001
RM
CS101 CS201 CS202
Alice X
Bob X X
Claire
Dan X X
-
8/2/2019 17 Representing Relations
10/28
10
Relations using matrices
What is it good for?
It is how computers view relations
A 2-dimensional array
Very easy to view relationship properties
We will generally consider relations on a
single set
In other words, the domain and co-domain are
the same set
And the matrix is square
-
8/2/2019 17 Representing Relations
11/28
11
Reflexivity
Consider a reflexive relation:
One which every element is related to itself
Let A = { 1, 2, 3, 4, 5 }
=
10000
11000
11100
11110
11111
M
If the center (main)
diagonal is all 1s, a
relation is reflexive
-
8/2/2019 17 Representing Relations
12/28
12
Irreflexivity
Consider a reflexive relation: