Relations
description
Transcript of Relations
![Page 1: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/1.jpg)
Relations
CSC-2259 Discrete Structures
Konstantin Busch - LSU 1
![Page 2: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/2.jpg)
Relations and Their Properties
Konstantin Busch - LSU 2
A binary relation from set tois a subset of Cartesian product
A BBA
Example: }2,1,0{A },{ baB
)},2(),,1(),,0(),,0{( babaR A relation:
![Page 3: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/3.jpg)
A relation on set :
Konstantin Busch - LSU 3
A relation on set is a subset ofA AA
Example:
}4,3,2,1{A
)}4,4(),1,4(),4,3(),2,2(),1,2(),2,1(),1,1{(R
![Page 4: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/4.jpg)
Konstantin Busch - LSU 4
Reflexive relation on set :R
RaaAa ),(,
Example: }4,3,2,1{A
)}4,4(),3,4(),3,3(),4,3(),2,2(),1,2(),2,1(),1,1{(R
A
![Page 5: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/5.jpg)
Konstantin Busch - LSU 5
Symmetric relation :R
RabRba ),(),(
Example: }4,3,2,1{A
)}4,4(),3,4(),4,3(),2,2(),1,2(),2,1(),1,1{(R
![Page 6: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/6.jpg)
Konstantin Busch - LSU 6
Antisymmetric relation :R
baRabRba ),(),(
Example: }4,3,2,1{A
)}4,4(),4,3(),2,2(),2,1(),1,1{(R
![Page 7: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/7.jpg)
Konstantin Busch - LSU 7
Transitive relation :R
RcaRcbRba ),(),(),(
Example: }4,3,2,1{A
)}4,2(),4,1(),3,1)(4,3(),3,2(),2,1(),1,1{(R
![Page 8: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/8.jpg)
Konstantin Busch - LSU 8
Combining Relations
))3,3(),2,2{(
)}1,1{(
)}3,3(),2,2(),4,1(),3,1(),2,1(),1,1{(
21
21
21
RR
RR
RR
)}3,3(),2,2(),1,1{(1 R
)}4,1(),3,1(),2,1(),1,1{(2 R
![Page 9: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/9.jpg)
Konstantin Busch - LSU 9
Composite relation:
)}4,3(),1,3(),3,2(),4,1(),1,1{(R
)}1,4(),2,3(),1,3(),0,2(),0,1{(S
)}1,3(),0,3(),2,2(),1,2(),1,1(),0,1{(RS
SbxRxaxRSba ),(),(:),( RS
Example:
RScaScbRba ),(),(),(Note:
![Page 10: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/10.jpg)
Konstantin Busch - LSU 10
Power of relation: nR
RR 1 RRR nn 1
Example: )}3,4(),2,3(),1,2(),1,1{(R
)}2,4)(1,3(),1,2(),1,1{(2 RRR
)}1,4)(1,3(),1,2(),1,1{(23 RRR 334 RRRR
![Page 11: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/11.jpg)
A relation is transitive if an only iffor all
Konstantin Busch - LSU 11
Theorem: RRRn
,3,2,1n
Proof: 1. If part: RR 2
2. Only if part: use induction
![Page 12: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/12.jpg)
We will show that if then is transitive
Konstantin Busch - LSU 12
1. If part: RR 2
R
RRR 2Definition of power:
Definition of composition:RRcaRcbRba ),(),(),(
RR 2
Rca ),(
Assumption:
Therefore, is transitiveR
![Page 13: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/13.jpg)
Konstantin Busch - LSU 13
2. Only if part:
We will show that if is transitive then for all
RRRn 1n
Proof by induction on
Inductive basis:
n
1n
RRR 1It trivially holds
![Page 14: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/14.jpg)
Konstantin Busch - LSU 14
Inductive hypothesis:
RRk Assume that
nk 1for all
![Page 15: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/15.jpg)
Konstantin Busch - LSU 15
Inductive step: RRn 1We will prove
1),( nRbaTake arbitrary
We will show Rba ),(
![Page 16: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/16.jpg)
Konstantin Busch - LSU 16
1),( nRba
RRba n ),(
nRbxRxax ),(),(:
RbxRxax ),(),(:
Rba ),(End of Proof
definition of power
definition of composition
inductive hypothesis RRn
is transitiveR
![Page 17: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/17.jpg)
n-ary relations
Konstantin Busch - LSU 17
An n-ary relation on setsis a subset of Cartesian product
nAAA ,,, 21 nAAA 21
Example: NNN A relation on
All triples of numbers with ),,( cba cba
}),5,2,1(),4,2,1(),3,2,1{( R
![Page 18: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/18.jpg)
Konstantin Busch - LSU 18
Professor Department Course-number
Cruz Zoology 335
Cruz Zoology 412
Farber Psychology 501
Farber Psychology 617
Rosen Comp. Science 518
Rosen Mathematics 575
Relational data model
fieldsR: Teaching assignments
records
primary key(all entries are different)
n-ary relation is represented with tableR
![Page 19: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/19.jpg)
Result of selection operator
Konstantin Busch - LSU 19
Selection operator: )(RsCkeeps all records that satisfy conditionC
Psychology Department : CExample:
Professor Department Course-number
Farber Psychology 501
Farber Psychology 617
)(RsC
![Page 20: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/20.jpg)
Konstantin Busch - LSU 20
Projection operator:
Keeps only the fields of
)(,,, 21RP
miii
miii ,,, 21
Example: )(Department Professor, RP
Professor Department
Cruz Zoology
Farber Psychology
Rosen Comp. Science
Rosen Mathematics
R
![Page 21: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/21.jpg)
Konstantin Busch - LSU 21
Join operator: ),( SRJ k
Concatenates the records of and where the last fields of are the same with the first fields of
R SR
Sk
k
![Page 22: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/22.jpg)
Konstantin Busch - LSU 22
Department Course-number
Room Time
Comp. Science
518 N521 2:00pm
Mathematics 575 N502 3:00pm
Mathematics 611 N521 4:00pm
Psychology 501 A100 3:00pm
Psychology 617 A110 11:00am
Zoology 335 A100 9:00am
Zoology 412 A100 8:00am
S: Class schedule
![Page 23: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/23.jpg)
Konstantin Busch - LSU 23
J2(R,S)Professor Departmen
tCourse Number
Room Time
Cruz Zoology 335 A100 9:00am
Cruz Zoology 412 A100 8:00am
Farber Psychology 501 A100 3:00pm
Farber Psychology 617 A110 11:00am
Rosen Comp. Science
518 N521 2:00pm
Rosen Mathematics 575 N502 3:00pm
![Page 24: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/24.jpg)
Representing Relations with Matrices
Konstantin Busch - LSU 24
10101
01101
00010
},,{ 321 aaaA },,,,{ 54321 bbbbbB
)},(),,(),,(),,(),,(),,(),,{( 53331342321221 babababababaaaR
1a
2a
3a
1b 2b 3b 4b 5b
A
BRM
Relation Matrix
![Page 25: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/25.jpg)
Konstantin Busch - LSU 25
Reflexive relation on set :RRaaAa ),(,
Example: }4,3,2,1{A)}4,4(),3,4(),3,3(),4,3(),2,2(),1,2(),2,1(),1,1{(R
A
11
11
11
111a
2a
3a
4a
1a 2a 3a 4a
Diagonal elements must be 1
![Page 26: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/26.jpg)
Konstantin Busch - LSU 26
11
1
11
111a
2a
3a
4a
1a 2a 3a 4a
Matrix is equal to its transpose:
Symmetric relation :R RabRba ),(),(
TRR MM
Example: }4,3,2,1{A
)}4,4(),3,4(),4,3(),2,2(),1,2(),2,1(),1,1{(R
],[],[ ijMjiM RR
ji,For all
![Page 27: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/27.jpg)
Konstantin Busch - LSU 27
11
1
11
11a
2a
3a
4a
1a 2a 3a 4a
Antisymmetric relation :R
Example: }4,3,2,1{A
],[],[ ijMjiM RR
baRabRba ),(),(
ji
)}4,4(),1,4(),4,3(),1,2(),2,2(),1,1{(R
For all
![Page 28: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/28.jpg)
Konstantin Busch - LSU 28
Union :
010
001
101
RM
001
110
101
SM
011
111
101
SRSR MMMSR
Intersection :SR
000
000
101
SRSR MMM
![Page 29: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/29.jpg)
Konstantin Busch - LSU 29
Composition :
000
011
101
RM
101
100
010
SM
000
110
111
SRRS MMM
RS Boolean matrix product
![Page 30: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/30.jpg)
Konstantin Busch - LSU 30
Power :
001
110
010
RM
010
111
110
2 RRRMMM
RRR 2 Boolean matrix product
![Page 31: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/31.jpg)
Konstantin Busch - LSU 31
Digraphs (Directed Graphs)
)},(),,(),,(),,(),,(),,(),,{( bdbcacdbbbdabaR
a b
d c
![Page 32: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/32.jpg)
Konstantin Busch - LSU 32
Theorem: nRba ),(
if and only ifthere is a path of length from to in
na b R
![Page 33: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/33.jpg)
Konstantin Busch - LSU 33
i
iRRRRR
1
321*
Connectivity relation:
*),( Rba if and only ifthere is some path (of any length) from to in a b R
![Page 34: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/34.jpg)
Konstantin Busch - LSU 34
nRRRRR 321*Theorem:
Proof: if thenfor some
1),( nRba iRba ),(},...,1{ ni
a bxRepeated node
![Page 35: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/35.jpg)
Closures and Relations
Konstantin Busch - LSU 35
Reflexive closure of :
Smallest size relation that containsand is reflexive
R
R
Easy to find
![Page 36: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/36.jpg)
Konstantin Busch - LSU 36
Symmetric closure of :
Smallest size relation that containsand is symmetric
R
R
Easy to find
![Page 37: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/37.jpg)
Konstantin Busch - LSU 37
Transitive closure of :
Smallest size relation that containsand is transitive
R
R
More difficult to find
![Page 38: Relations](https://reader036.fdocuments.in/reader036/viewer/2022070403/568139c3550346895da16994/html5/thumbnails/38.jpg)
If and is transitive
Konstantin Busch - LSU 38
is the transitive Closure ofRTheorem: *R
Proof:*R is transitivePart 1:
Part 2: SR S
Then SSR **