SlideShare a Scribd company logo
1 of 28
1
Representing Relations
Epp section ???
CS 202
Aaron Bloomfield
2
In this slide set…
• Matrix review
• Two ways to represent relations
– Via matrices
– Via directed graphs
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 Boolean
operations
– 1 is true, 0 is false












0
1
0
1
0
1
0
1
0
0
1
0
0
0
0
1
4
Matrix transposition
• Given a matrix M, the transposition of M, denoted Mt, is
the matrix obtained by switching the columns and rows
of M
• In a “square” matrix, the main
diagonal stays unchanged







6
5
4
3
2
1
M













16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
M











6
3
5
2
4
1
t
M













16
12
8
4
15
11
7
3
14
10
6
2
13
9
5
1
t
M
5
Matrix join
• A join 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: 






































0
1
1
1
1
1
0
1
0
1
1
0
0
1
1
1
0
0
1
1
1
1
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
0
1
0
0
0
0
1
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: 






































0
0
0
1
0
1
0
0
0
0
1
0
0
0
0
0
0
0
1
1
1
1
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
0
1
0
0
0
0
1
7
Matrix Boolean product
• A Boolean product of two matrices is similar to matrix
multiplication
– Instead of the sum of the products, it’s the conjunction (and) of
the disjunctions (ors)
– Denoted by the or symbol:
1
,
4
4
,
1
1
,
3
3
,
1
1
,
2
2
,
1
1
,
1
1
,
1
1
,
1 *
*
*
* b
a
b
a
b
a
b
a
c 



1
,
4
4
,
1
1
,
3
3
,
1
1
,
2
2
,
1
1
,
1
1
,
1
1
,
1 b
a
b
a
b
a
b
a
c 












































1
1
1
0
1
1
1
0
0
1
1
0
0
1
1
0
0
0
1
1
1
1
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
0
1
0
0
0
0
1




































 0
0
0
1
1
1
1
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
0
1
0
0
0
0
1





































0
0
1
1
1
1
0
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
0
1
0
0
0
0
1

8
Relations using matrices
• List the elements of sets A and B in a
particular order
– Order doesn’t matter, but we’ll generally use
ascending order
• Create a matrix ]
[ ij
R m

M








R
b
a
R
b
a
m
j
i
j
i
ij
)
,
(
if
0
)
,
(
if
1
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 }













1
1
0
0
0
0
1
1
0
0
0
1
R
M
CS101 CS201 CS202
Alice X
Bob X X
Claire
Dan X X
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
11
Reflexivity
• Consider a reflexive relation: ≤
– One which every element is related to itself
– Let A = { 1, 2, 3, 4, 5 }


















1
0
0
0
0
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
1
1
1
1
1
M
If the center (main)
diagonal is all 1’s, a
relation is reflexive
12
Irreflexivity
• Consider a reflexive relation: <
– One which every element is not related to itself
– Let A = { 1, 2, 3, 4, 5 }


















0
0
0
0
0
1
0
0
0
0
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
M
If the center (main)
diagonal is all 0’s, a
relation is irreflexive
13


















1
0
0
1
0
0
1
0
0
1
0
0
0
0
1
1
0
0
0
0
0
1
1
0
1
M
Symmetry
• Consider an symmetric relation R
– One which if a is related to b then b is related to a for
all (a,b)
– Let A = { 1, 2, 3, 4, 5 }
• If, for every value, it is
the equal to the value in
its transposed position,
then the relation is
symmetric
14


















0
0
0
0
0
1
0
0
0
0
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
M
Asymmetry
• Consider an asymmetric relation: <
– One which if a is related to b then b is not related to a
for all (a,b)
– Let A = { 1, 2, 3, 4, 5 } • If, for every value and
the value in its
transposed position, if
they are not both 1,
then the relation is
asymmetric
• An asymmetric relation
must also be irreflexive
• Thus, the main
diagonal must be all 0’s
15


















1
0
0
0
0
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
1
1
1
1
1
M
Antisymmetry
• Consider an antisymmetric relation: ≤
– One which if a is related to b then b is not related to a
unless a=b for all (a,b)
– Let A = { 1, 2, 3, 4, 5 } • If, for every value
and the value in its
transposed position,
if they are not both 1,
then the relation is
antisymmetric
• The center diagonal
can have both 1’s
and 0’s
16
Transitivity
• Consider an transitive relation: ≤
– One which if a is related to b and b is related to c then
a is related to c for all (a,b), (b,c) and (a,c)
– Let A = { 1, 2, 3, 4, 5 }


















1
0
0
0
0
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
1
1
1
1
1
M
• If, for every spot (a,b)
and (b,c) that each
have a 1, there is a 1
at (a,c), then the
relation is transitive
• Matrices don’t show
this property easily
17
Combining relations:
via Boolean operators
• Let:
• Join:
• Meet:











0
1
0
0
0
1
1
0
1
R
M











0
0
1
1
1
0
1
0
1
S
M













0
1
1
1
1
1
1
0
1
S
R
S
R M
M
M 













0
0
0
0
0
0
1
0
1
S
R
S
R M
M
M 
18
Combining relations:
via relation composition
• Let:
• But why is this the case?











0
1
0
0
0
1
1
0
1
R
M











0
0
1
1
1
0
1
0
1
S
M













0
1
0
1
0
1
1
0
1
S
R
R
S M
M
M 
a
b
c
d
e
f
d e f g h i
a
b
c
g h i
19
Representing relations using
directed graphs
• A directed graph consists of:
– A set V of vertices (or nodes)
– A set E of edges (or arcs)
– If (a, b) is in the relation, then there is an arrow from a to b
• Will generally use relations on a single set
• Consider our relation R = { (a,b) | a divides b }
• Old way:
1
2
3
4
1
2
3
4
1 2
3 4
20
Reflexivity
• Consider a reflexive relation: ≤
– One which every element is related to itself
– Let A = { 1, 2, 3, 4, 5 }
If every node has a
loop, a relation is
reflexive
1 2
5 3
4
21
Irreflexivity
• Consider a reflexive relation: <
– One which every element is not related to itself
– Let A = { 1, 2, 3, 4, 5 }
If every node does
not have a loop, a
relation is irreflexive
1 2
5 3
4
22
Symmetry
• Consider an symmetric relation R
– One which if a is related to b then b is related to a for
all (a,b)
– Let A = { 1, 2, 3, 4, 5 }
• If, for every edge, there
is an edge in the other
direction, then the
relation is symmetric
• Loops are allowed, and
do not need edges in the
“other” direction
1 2
5 3
4 Note that this relation is neither
reflexive nor irreflexive!
Called anti-
parallel pairs
23
Asymmetry
• Consider an asymmetric relation: <
– One which if a is related to b then b is not related to a
for all (a,b)
– Let A = { 1, 2, 3, 4, 5 }
• A digraph is asymmetric if:
1. If, for every edge, there is
not an edge in the other
direction, then the relation
is asymmetric
2. Loops are not allowed in
an asymmetric digraph
(recall it must be
irreflexive)
1 2
5 3
4
24
Antisymmetry
• Consider an antisymmetric relation: ≤
– One which if a is related to b then b is not related to a
unless a=b for all (a,b)
– Let A = { 1, 2, 3, 4, 5 }
1 2
5 3
4
• If, for every edge, there is
not an edge in the other
direction, then the relation
is antisymmetric
• Loops are allowed in the
digraph
25
Transitivity
• Consider an transitive relation: ≤
– One which if a is related to b and b is related to c then
a is related to c for all (a,b), (b,c) and (a,c)
– Let A = { 1, 2, 3, 4, 5 }
1 2
5 3
4
• A digraph is transitive if, for
there is a edge from a to c
when there is a edge from
a to b and from b to c
26
Applications of digraphs: MapQuest
Start
End
•Not reflexive
•Is irreflexive
•Not symmetric
•Not asymmetric
•Not antisymmetric
•Not transitive
•Not reflexive
•Is irreflexive
•Is symmetric
•Not asymmetric
•Not antisymmetric
•Not transitive
27
Sample questions
Which of the graphs are reflexive,
irreflexive, symmetric, asymmetric,
antisymmetric, or transitive
23 24 25 26 27 28
Reflexive Y Y Y
Irreflexive Y Y
Symmetric Y Y
Asymmetric Y
Anti-
symmetric
Y Y
Transitive Y
28
How many symmetric relations are
there on a set with n elements?
• Consider the matrix representing symmetric relation R on a set with
n elements:
• The center diagonal can have any values
• Once the “upper” triangle is determined,
the “lower” triangle must be the transposed
version of the “upper” one
• How many ways are there to fill in the center
diagonal and the upper triangle?
• There are n2 elements in the matrix
• There are n elements in the center diagonal
– Thus, there are 2n ways to fill in 0’s and 1’s in the diagonal
• Thus, there are (n2-n)/2 elements in each triangle
– Thus, there are ways to fill in 0’s and 1’s in the triangle
• Answer: there are possible symmetric
relations on a set with n elements
















1
0
1
0
0
0
1
1
0
1





2
/
)
( 2
2 n
n 
2
/
)
(
2
/
)
( 2
2
2
2
*
2 n
n
n
n
n 



More Related Content

Similar to Representing-relations.ppt

Regression and Co-Relation
Regression and Co-RelationRegression and Co-Relation
Regression and Co-Relationnuwan udugampala
 
Copy_of_slopeofaline (1).ppt
Copy_of_slopeofaline (1).pptCopy_of_slopeofaline (1).ppt
Copy_of_slopeofaline (1).pptLeianMartin1
 
Copy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptCopy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptchinnurulz
 
Regression analysis
Regression analysisRegression analysis
Regression analysisSrikant001p
 
Linear Equation in one variables 3
Linear Equation in one variables 3Linear Equation in one variables 3
Linear Equation in one variables 3NG YIT HOE
 
Correlation analysis
Correlation analysis Correlation analysis
Correlation analysis Anil Pokhrel
 
Linear equation in one variable PPT.pdf
Linear equation in one variable PPT.pdfLinear equation in one variable PPT.pdf
Linear equation in one variable PPT.pdfmanojindustry
 
Correlation _ Regression Analysis statistics.pptx
Correlation _ Regression Analysis statistics.pptxCorrelation _ Regression Analysis statistics.pptx
Correlation _ Regression Analysis statistics.pptxkrunal soni
 
Mathematics in the Modern World (Patterns and Sequences).pptx
Mathematics in the Modern World (Patterns and Sequences).pptxMathematics in the Modern World (Patterns and Sequences).pptx
Mathematics in the Modern World (Patterns and Sequences).pptxReignAnntonetteYayai
 
Parallel and Perpendicular Slopes lines
Parallel and Perpendicular Slopes linesParallel and Perpendicular Slopes lines
Parallel and Perpendicular Slopes linesswartzje
 
Correlation and regression
Correlation and regressionCorrelation and regression
Correlation and regressionANCYBS
 
AP Advantage: AP Calculus
AP Advantage: AP CalculusAP Advantage: AP Calculus
AP Advantage: AP CalculusShashank Patil
 
Straight_Lines in mat 111 full lecture.ppt
Straight_Lines in mat 111 full lecture.pptStraight_Lines in mat 111 full lecture.ppt
Straight_Lines in mat 111 full lecture.pptElaiyarajaR1
 
Finite mathematics
Finite mathematicsFinite mathematics
Finite mathematicsIgor Rivin
 
Sat index cards
Sat index cardsSat index cards
Sat index cardstschmucker
 

Similar to Representing-relations.ppt (20)

Regression and Co-Relation
Regression and Co-RelationRegression and Co-Relation
Regression and Co-Relation
 
Copy_of_slopeofaline (1).ppt
Copy_of_slopeofaline (1).pptCopy_of_slopeofaline (1).ppt
Copy_of_slopeofaline (1).ppt
 
Copy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptCopy_of_slopeofaline.ppt
Copy_of_slopeofaline.ppt
 
Copy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptCopy_of_slopeofaline.ppt
Copy_of_slopeofaline.ppt
 
Copy_of_slopeofaline.ppt
Copy_of_slopeofaline.pptCopy_of_slopeofaline.ppt
Copy_of_slopeofaline.ppt
 
Regression analysis
Regression analysisRegression analysis
Regression analysis
 
Linear Algebra
Linear AlgebraLinear Algebra
Linear Algebra
 
Linear Equation in one variables 3
Linear Equation in one variables 3Linear Equation in one variables 3
Linear Equation in one variables 3
 
Correlation analysis
Correlation analysis Correlation analysis
Correlation analysis
 
Linear equation in one variable PPT.pdf
Linear equation in one variable PPT.pdfLinear equation in one variable PPT.pdf
Linear equation in one variable PPT.pdf
 
Correlation _ Regression Analysis statistics.pptx
Correlation _ Regression Analysis statistics.pptxCorrelation _ Regression Analysis statistics.pptx
Correlation _ Regression Analysis statistics.pptx
 
Mathematics in the Modern World (Patterns and Sequences).pptx
Mathematics in the Modern World (Patterns and Sequences).pptxMathematics in the Modern World (Patterns and Sequences).pptx
Mathematics in the Modern World (Patterns and Sequences).pptx
 
Parallel and Perpendicular Slopes lines
Parallel and Perpendicular Slopes linesParallel and Perpendicular Slopes lines
Parallel and Perpendicular Slopes lines
 
Correlation and regression
Correlation and regressionCorrelation and regression
Correlation and regression
 
AP Advantage: AP Calculus
AP Advantage: AP CalculusAP Advantage: AP Calculus
AP Advantage: AP Calculus
 
LINES AND ANGLES.pptx
LINES AND ANGLES.pptxLINES AND ANGLES.pptx
LINES AND ANGLES.pptx
 
Straight_Lines in mat 111 full lecture.ppt
Straight_Lines in mat 111 full lecture.pptStraight_Lines in mat 111 full lecture.ppt
Straight_Lines in mat 111 full lecture.ppt
 
Finite mathematics
Finite mathematicsFinite mathematics
Finite mathematics
 
Sat index cards
Sat index cardsSat index cards
Sat index cards
 
PCA.ppt
PCA.pptPCA.ppt
PCA.ppt
 

More from PerumalPitchandi

Lecture Notes on Recommender System Introduction
Lecture Notes on Recommender System IntroductionLecture Notes on Recommender System Introduction
Lecture Notes on Recommender System IntroductionPerumalPitchandi
 
22ADE002 – Business Analytics- Module 1.pptx
22ADE002 – Business Analytics- Module 1.pptx22ADE002 – Business Analytics- Module 1.pptx
22ADE002 – Business Analytics- Module 1.pptxPerumalPitchandi
 
Descriptive_Statistics_PPT.ppt
Descriptive_Statistics_PPT.pptDescriptive_Statistics_PPT.ppt
Descriptive_Statistics_PPT.pptPerumalPitchandi
 
20IT204-COA-Lecture 18.ppt
20IT204-COA-Lecture 18.ppt20IT204-COA-Lecture 18.ppt
20IT204-COA-Lecture 18.pptPerumalPitchandi
 
20IT204-COA- Lecture 17.pptx
20IT204-COA- Lecture 17.pptx20IT204-COA- Lecture 17.pptx
20IT204-COA- Lecture 17.pptxPerumalPitchandi
 
Capability Maturity Model (CMM).pptx
Capability Maturity Model (CMM).pptxCapability Maturity Model (CMM).pptx
Capability Maturity Model (CMM).pptxPerumalPitchandi
 
Comparison_between_Waterfall_and_Agile_m (1).pptx
Comparison_between_Waterfall_and_Agile_m (1).pptxComparison_between_Waterfall_and_Agile_m (1).pptx
Comparison_between_Waterfall_and_Agile_m (1).pptxPerumalPitchandi
 
Introduction to Data Science.pptx
Introduction to Data Science.pptxIntroduction to Data Science.pptx
Introduction to Data Science.pptxPerumalPitchandi
 
FDS Module I 24.1.2022.ppt
FDS Module I 24.1.2022.pptFDS Module I 24.1.2022.ppt
FDS Module I 24.1.2022.pptPerumalPitchandi
 
FDS Module I 20.1.2022.ppt
FDS Module I 20.1.2022.pptFDS Module I 20.1.2022.ppt
FDS Module I 20.1.2022.pptPerumalPitchandi
 
AgileSoftwareDevelopment.ppt
AgileSoftwareDevelopment.pptAgileSoftwareDevelopment.ppt
AgileSoftwareDevelopment.pptPerumalPitchandi
 
Agile and its impact to Project Management 022218.pptx
Agile and its impact to Project Management 022218.pptxAgile and its impact to Project Management 022218.pptx
Agile and its impact to Project Management 022218.pptxPerumalPitchandi
 

More from PerumalPitchandi (20)

Lecture Notes on Recommender System Introduction
Lecture Notes on Recommender System IntroductionLecture Notes on Recommender System Introduction
Lecture Notes on Recommender System Introduction
 
22ADE002 – Business Analytics- Module 1.pptx
22ADE002 – Business Analytics- Module 1.pptx22ADE002 – Business Analytics- Module 1.pptx
22ADE002 – Business Analytics- Module 1.pptx
 
biv_mult.ppt
biv_mult.pptbiv_mult.ppt
biv_mult.ppt
 
ppt_ids-data science.pdf
ppt_ids-data science.pdfppt_ids-data science.pdf
ppt_ids-data science.pdf
 
ANOVA Presentation.ppt
ANOVA Presentation.pptANOVA Presentation.ppt
ANOVA Presentation.ppt
 
Data Science Intro.pptx
Data Science Intro.pptxData Science Intro.pptx
Data Science Intro.pptx
 
Descriptive_Statistics_PPT.ppt
Descriptive_Statistics_PPT.pptDescriptive_Statistics_PPT.ppt
Descriptive_Statistics_PPT.ppt
 
SW_Cost_Estimation.ppt
SW_Cost_Estimation.pptSW_Cost_Estimation.ppt
SW_Cost_Estimation.ppt
 
CostEstimation-1.ppt
CostEstimation-1.pptCostEstimation-1.ppt
CostEstimation-1.ppt
 
20IT204-COA-Lecture 18.ppt
20IT204-COA-Lecture 18.ppt20IT204-COA-Lecture 18.ppt
20IT204-COA-Lecture 18.ppt
 
20IT204-COA- Lecture 17.pptx
20IT204-COA- Lecture 17.pptx20IT204-COA- Lecture 17.pptx
20IT204-COA- Lecture 17.pptx
 
Capability Maturity Model (CMM).pptx
Capability Maturity Model (CMM).pptxCapability Maturity Model (CMM).pptx
Capability Maturity Model (CMM).pptx
 
Comparison_between_Waterfall_and_Agile_m (1).pptx
Comparison_between_Waterfall_and_Agile_m (1).pptxComparison_between_Waterfall_and_Agile_m (1).pptx
Comparison_between_Waterfall_and_Agile_m (1).pptx
 
Introduction to Data Science.pptx
Introduction to Data Science.pptxIntroduction to Data Science.pptx
Introduction to Data Science.pptx
 
FDS Module I 24.1.2022.ppt
FDS Module I 24.1.2022.pptFDS Module I 24.1.2022.ppt
FDS Module I 24.1.2022.ppt
 
FDS Module I 20.1.2022.ppt
FDS Module I 20.1.2022.pptFDS Module I 20.1.2022.ppt
FDS Module I 20.1.2022.ppt
 
AgileSoftwareDevelopment.ppt
AgileSoftwareDevelopment.pptAgileSoftwareDevelopment.ppt
AgileSoftwareDevelopment.ppt
 
Agile and its impact to Project Management 022218.pptx
Agile and its impact to Project Management 022218.pptxAgile and its impact to Project Management 022218.pptx
Agile and its impact to Project Management 022218.pptx
 
Data_exploration.ppt
Data_exploration.pptData_exploration.ppt
Data_exploration.ppt
 
state-spaces29Sep06.ppt
state-spaces29Sep06.pptstate-spaces29Sep06.ppt
state-spaces29Sep06.ppt
 

Recently uploaded

Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 

Recently uploaded (20)

Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 

Representing-relations.ppt

  • 1. 1 Representing Relations Epp section ??? CS 202 Aaron Bloomfield
  • 2. 2 In this slide set… • Matrix review • Two ways to represent relations – Via matrices – Via directed graphs
  • 3. 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 Boolean operations – 1 is true, 0 is false             0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 1
  • 4. 4 Matrix transposition • Given a matrix M, the transposition of M, denoted Mt, is the matrix obtained by switching the columns and rows of M • In a “square” matrix, the main diagonal stays unchanged        6 5 4 3 2 1 M              16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 M            6 3 5 2 4 1 t M              16 12 8 4 15 11 7 3 14 10 6 2 13 9 5 1 t M
  • 5. 5 Matrix join • A join 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:                                        0 1 1 1 1 1 0 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 1
  • 6. 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:                                        0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 1
  • 7. 7 Matrix Boolean product • A Boolean product of two matrices is similar to matrix multiplication – Instead of the sum of the products, it’s the conjunction (and) of the disjunctions (ors) – Denoted by the or symbol: 1 , 4 4 , 1 1 , 3 3 , 1 1 , 2 2 , 1 1 , 1 1 , 1 1 , 1 * * * * b a b a b a b a c     1 , 4 4 , 1 1 , 3 3 , 1 1 , 2 2 , 1 1 , 1 1 , 1 1 , 1 b a b a b a b a c                                              1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 1                                      0 0 0 1 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 1                                      0 0 1 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1 0 0 0 0 1 
  • 8. 8 Relations using matrices • List the elements of sets A and B in a particular order – Order doesn’t matter, but we’ll generally use ascending order • Create a matrix ] [ ij R m  M         R b a R b a m j i j i ij ) , ( if 0 ) , ( if 1
  • 9. 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 }              1 1 0 0 0 0 1 1 0 0 0 1 R M CS101 CS201 CS202 Alice X Bob X X Claire Dan X X
  • 10. 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
  • 11. 11 Reflexivity • Consider a reflexive relation: ≤ – One which every element is related to itself – Let A = { 1, 2, 3, 4, 5 }                   1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 1 1 0 1 1 1 1 1 M If the center (main) diagonal is all 1’s, a relation is reflexive
  • 12. 12 Irreflexivity • Consider a reflexive relation: < – One which every element is not related to itself – Let A = { 1, 2, 3, 4, 5 }                   0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 1 1 0 M If the center (main) diagonal is all 0’s, a relation is irreflexive
  • 13. 13                   1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 0 1 M Symmetry • Consider an symmetric relation R – One which if a is related to b then b is related to a for all (a,b) – Let A = { 1, 2, 3, 4, 5 } • If, for every value, it is the equal to the value in its transposed position, then the relation is symmetric
  • 14. 14                   0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 1 1 0 M Asymmetry • Consider an asymmetric relation: < – One which if a is related to b then b is not related to a for all (a,b) – Let A = { 1, 2, 3, 4, 5 } • If, for every value and the value in its transposed position, if they are not both 1, then the relation is asymmetric • An asymmetric relation must also be irreflexive • Thus, the main diagonal must be all 0’s
  • 15. 15                   1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 1 1 0 1 1 1 1 1 M Antisymmetry • Consider an antisymmetric relation: ≤ – One which if a is related to b then b is not related to a unless a=b for all (a,b) – Let A = { 1, 2, 3, 4, 5 } • If, for every value and the value in its transposed position, if they are not both 1, then the relation is antisymmetric • The center diagonal can have both 1’s and 0’s
  • 16. 16 Transitivity • Consider an transitive relation: ≤ – One which if a is related to b and b is related to c then a is related to c for all (a,b), (b,c) and (a,c) – Let A = { 1, 2, 3, 4, 5 }                   1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 1 1 0 1 1 1 1 1 M • If, for every spot (a,b) and (b,c) that each have a 1, there is a 1 at (a,c), then the relation is transitive • Matrices don’t show this property easily
  • 17. 17 Combining relations: via Boolean operators • Let: • Join: • Meet:            0 1 0 0 0 1 1 0 1 R M            0 0 1 1 1 0 1 0 1 S M              0 1 1 1 1 1 1 0 1 S R S R M M M               0 0 0 0 0 0 1 0 1 S R S R M M M 
  • 18. 18 Combining relations: via relation composition • Let: • But why is this the case?            0 1 0 0 0 1 1 0 1 R M            0 0 1 1 1 0 1 0 1 S M              0 1 0 1 0 1 1 0 1 S R R S M M M  a b c d e f d e f g h i a b c g h i
  • 19. 19 Representing relations using directed graphs • A directed graph consists of: – A set V of vertices (or nodes) – A set E of edges (or arcs) – If (a, b) is in the relation, then there is an arrow from a to b • Will generally use relations on a single set • Consider our relation R = { (a,b) | a divides b } • Old way: 1 2 3 4 1 2 3 4 1 2 3 4
  • 20. 20 Reflexivity • Consider a reflexive relation: ≤ – One which every element is related to itself – Let A = { 1, 2, 3, 4, 5 } If every node has a loop, a relation is reflexive 1 2 5 3 4
  • 21. 21 Irreflexivity • Consider a reflexive relation: < – One which every element is not related to itself – Let A = { 1, 2, 3, 4, 5 } If every node does not have a loop, a relation is irreflexive 1 2 5 3 4
  • 22. 22 Symmetry • Consider an symmetric relation R – One which if a is related to b then b is related to a for all (a,b) – Let A = { 1, 2, 3, 4, 5 } • If, for every edge, there is an edge in the other direction, then the relation is symmetric • Loops are allowed, and do not need edges in the “other” direction 1 2 5 3 4 Note that this relation is neither reflexive nor irreflexive! Called anti- parallel pairs
  • 23. 23 Asymmetry • Consider an asymmetric relation: < – One which if a is related to b then b is not related to a for all (a,b) – Let A = { 1, 2, 3, 4, 5 } • A digraph is asymmetric if: 1. If, for every edge, there is not an edge in the other direction, then the relation is asymmetric 2. Loops are not allowed in an asymmetric digraph (recall it must be irreflexive) 1 2 5 3 4
  • 24. 24 Antisymmetry • Consider an antisymmetric relation: ≤ – One which if a is related to b then b is not related to a unless a=b for all (a,b) – Let A = { 1, 2, 3, 4, 5 } 1 2 5 3 4 • If, for every edge, there is not an edge in the other direction, then the relation is antisymmetric • Loops are allowed in the digraph
  • 25. 25 Transitivity • Consider an transitive relation: ≤ – One which if a is related to b and b is related to c then a is related to c for all (a,b), (b,c) and (a,c) – Let A = { 1, 2, 3, 4, 5 } 1 2 5 3 4 • A digraph is transitive if, for there is a edge from a to c when there is a edge from a to b and from b to c
  • 26. 26 Applications of digraphs: MapQuest Start End •Not reflexive •Is irreflexive •Not symmetric •Not asymmetric •Not antisymmetric •Not transitive •Not reflexive •Is irreflexive •Is symmetric •Not asymmetric •Not antisymmetric •Not transitive
  • 27. 27 Sample questions Which of the graphs are reflexive, irreflexive, symmetric, asymmetric, antisymmetric, or transitive 23 24 25 26 27 28 Reflexive Y Y Y Irreflexive Y Y Symmetric Y Y Asymmetric Y Anti- symmetric Y Y Transitive Y
  • 28. 28 How many symmetric relations are there on a set with n elements? • Consider the matrix representing symmetric relation R on a set with n elements: • The center diagonal can have any values • Once the “upper” triangle is determined, the “lower” triangle must be the transposed version of the “upper” one • How many ways are there to fill in the center diagonal and the upper triangle? • There are n2 elements in the matrix • There are n elements in the center diagonal – Thus, there are 2n ways to fill in 0’s and 1’s in the diagonal • Thus, there are (n2-n)/2 elements in each triangle – Thus, there are ways to fill in 0’s and 1’s in the triangle • Answer: there are possible symmetric relations on a set with n elements                 1 0 1 0 0 0 1 1 0 1      2 / ) ( 2 2 n n  2 / ) ( 2 / ) ( 2 2 2 2 * 2 n n n n n   