210-ch8-part1
TRANSCRIPT
-
8/9/2019 210-ch8-part1
1/34
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007
Chapter 8: Relations
Relations(8.1)
n-any Relations & their Applications (8.2)
-
8/9/2019 210-ch8-part1
2/34
2
Relations (8.1)
Introduction
– Relationship beteen a pro!ra" and its
#ariables
– Inte!ers that are con!ruent "odulo $
– %airs o cities lin$ed by airline li!hts in a
netor$
-
8/9/2019 210-ch8-part1
3/34
Relations (8.1) (cont.)
Relations & their properties
– 'einition 1
et A and be sets. A binary relation ro" A to is a subset o A * .
In other ords+ a binary relation ro" A to isa set R o ordered pairs here the irstele"ent o each ordered pair co"es ro" Aand the second ele"ent co"es ro" .
-
8/9/2019 210-ch8-part1
4/34
(
Relations (8.1) (cont.)
– ,otation:
aRb ⇔ (a+ b) ∈ R
aRb ⇔ (a+ b) ∉ R
R a b
0
1
2
X X
X
X
0
1
2
a
b
-
8/9/2019 210-ch8-part1
5/34
'
Relations (8.1) (cont.)
– a"ple: A / set o all cities
/ set o the 0 states in the 3A
'eine the relation R by speciyin! that (a+ b)
belon!s to R i city a is in state b.
R.inare
) New Jersey Bank, Red
)California ,(Cupertino
) Michigan , Aror Ann( ) Maine , Bangor (
)Colorado , Boulder (
-
8/9/2019 210-ch8-part1
6/34
/
Relations (8.1) (cont.)
4unctions as relations
– 5he !raph o a unction is the set o orderedpairs (a+ b) such that b / (a)
– 5he !raph o is a subset o A * ⇒ it is arelation ro" A to
– Con#ersely+ i R is a relation ro" A to suchthat e#ery ele"ent in A is the irst ele"ent oeactly one ordered pair o R+ then a unctioncan be deined ith R as its !raph
-
8/9/2019 210-ch8-part1
7/34
7
Relations (8.1) (cont.)
Relations on a set
– 'einition 2
A relation on the set A is a relation ro" A to A.
– a"ple: A / set 61+ 2+ 7+ 9. hich ordered pairs arein the relation R / 6(a+ b) ; a di#ides b9
Solution: 3ince (a+ b) is in R i and only i a and b arepositi#e inte!ers not eceedin! such that a di#ides b
R / 6(1+1)+ (1+2)+ (1.7)+ (1.)+ (2+2)+ (2+)+ (7+7)+ (+)9
-
8/9/2019 210-ch8-part1
8/34
Relations (8.1) (cont.)
%roperties o Relations
– 'einition 7
A relation R on a set A is called relei#e i
(a+ a) ∈ R or e#ery ele"ent a ∈ A.
-
8/9/2019 210-ch8-part1
9/34
Relations (8.1) (cont.)
– a"ple (a): Consider the olloin! relationson 61+ 2+ 7+ 9
R1 / 6(1+1)+ (1+2)+ (2+1)+ (2+2)+ (7+)+ (+1)+ (+)9
R2 / 6(1+1)+ (1+2)+ (2+1)9R7 / 6(1+1)+ (1+2)+ (1+)+ (2+1)+ (2+2)+ (7+7)+ (7+)+ (+1)+(+)9R8 / 6(2+1)+ (7+1)+ (7+2)+ (+1)+ (+2)+ (+7)9R0 / 6(1+1)+ (1+2)+ (1+7)+ (1+)+ (2+2)+ (2+7)+ (2+)+ (7+7)+
(7+)+ (+)9R
-
8/9/2019 210-ch8-part1
10/34
10
Relations (8.1) (cont.)
Solution:
R7 and R0: relei#e ⇐ both contain all pairs
o the or" (a+ a): (1+1)+ (2+2)+ (7+7) & (+).
R1+ R2+ R8 and R
-
8/9/2019 210-ch8-part1
11/34
11
Relations (8.1) (cont.)
– 'einition :
A relation R on a set A is called sy""etric i
(b+ a) ∈ R hene#er (a+ b) ∈ R+ or all a+b ∈ A.
A relation R on a set A such that (a+ b) ∈ R
and (b+ a) ∈ R only i a / b+ or all a+ b ∈ A+ is
called antisy""etric.
-
8/9/2019 210-ch8-part1
12/34
12
Relations (8.1) (cont.)
– a"ple: hich o the relations ro" ea"ple (a) aresy""etric and hich are antisy""etric=
Solution:
R2 & R7: sy""etric ⇐ each case (b+ a) belon!s to the relation
hene#er (a+ b) does.
4or R2: only thin! to chec$ that both (1+2) & (2+1) belon! to the
relation
4or R7: it is necessary to chec$ that both (1+2) & (2+1) belon! to
the relation.
,one o the other relations is sy""etric: ind a pair (a+ b) so
that it is in the relation but (b+ a) is not.
R1 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)}
R2 = {(1,1), (1,2), (2,1)}
R3 = {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (4,1), (4,4)}
R4 = {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)}
R5 = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)}R6 = {(3,4)}
-
8/9/2019 210-ch8-part1
13/34
1
Relations (8.1) (cont.)
Solution (cont.):
R8+ R0 and R
-
8/9/2019 210-ch8-part1
14/34
1(
Relations (8.1) (cont.)
– 'einition 0:
A relation R on a set A is called transiti#e ihene#er (a+ b) ∈ R and (b+c) ∈ R+ then
(a+ c) ∈ R+ or all a+ b+ c ∈ R.
-
8/9/2019 210-ch8-part1
15/34
1'
Relations (8.1) (cont.)
– a"ple: hich o the relations in ea"ple (a) aretransiti#e=
R + R0 & R
-
8/9/2019 210-ch8-part1
16/34
1/
Relations (8.1) (cont.)
Co"binin! relations
– a"ple:
et A / 61+ 2+ 79 and / 61+ 2+ 7+ + 9. 5he relations R1 / 6(1+1)+ (2+2)+ (7+7)9 and
R2 / 6(1+1)+ (1+2)+ (1+7)+ (1+)9 can be co"bined to
obtain:
R1 ∪ R2 / 6(1+1)+ (1+2)+ (1+7)+ (1+)+ (2+2)+ (7+7)9
R1∩ R2 / 6(1+1)9
R1 – R2 / 6(2+2)+ (7+7)9
R2 – R1 / 6(1+2)+ (1+7)+ (1+)9
-
8/9/2019 210-ch8-part1
17/34
17
Relations (8.1) (cont.)
– 'einition
-
8/9/2019 210-ch8-part1
18/34
1
Relations (8.1) (cont.)
– a"ple: hat is the co"posite o the relations Rand 3 here R is the relation ro" 61+2+79 to 61+2+7+9ith R / 6(1+1)+ (1+)+ (2+7)+ (7+1)+ (7+)9 and 3 is therelation ro" 61+2+7+9 to 6+1+29 ith 3 / 6(1+)+ (2+)+(7+1)+ (7+2)+ (+1)9=
Solution: 3 ° R is constructed usin! all ordered pairsin R and ordered pairs in 3+ here the secondele"ent o the ordered in R a!rees ith the irst
ele"ent o the ordered pair in 3.4or ea"ple+ the ordered pairs (2+7) in R and (7+1) in3 produce the ordered pair (2+1) in 3 ° R. Co"putin!all the ordered pairs in the co"posite+ e ind
3 ° R / ((1+)+ (1+1)+ (2+1)+ (2+2)+ (7+)+ (7+1)9
-
8/9/2019 210-ch8-part1
19/34
1
,-ary Relations & their Applications (8.2)
Relationship a"on! ele"ents o "ore
than 2 sets oten arise: n-ary relations
Airline+ li!ht nu"ber+ startin! point+
destination+ departure ti"e+ arri#al ti"e
20
-
8/9/2019 210-ch8-part1
20/34
20
,-ary Relations & their Applications (8.2) (cont.)
,-ary relations
– 'einition 1:
et A1+ A2+ >+ An be sets. An n-ary relation on thesesets is a subset o A1 * A2 *>* An here Ai are the
do"ains o the relation+ and n is called its de!ree.
– a"ple: et R be the relation on , * , * , consistin!o triples (a+ b+ c) here a+ b+ and c are inte!ers ith
a?b?c. 5hen (1+2+7) ∈ R+ but
(2++7) ∉ R. 5he de!ree o this relation is 7. Its
do"ains are e@ual to the set o inte!ers.
21
-
8/9/2019 210-ch8-part1
21/34
21
,-ary Relations & their Applications (8.2) (cont.)
'atabases & Relations
– Relational database "odel has been de#elopedor inor"ation processin!
– A database consists o records+ hich are n-tuples "ade up o ields
– 5he ields contains inor"ation such as: ,a"e
3tudent B
aDor
Erade point a#era!e o the student
22
-
8/9/2019 210-ch8-part1
22/34
22
,-ary Relations & their Applications (8.2) (cont.)
– 5he relational database "odel represents a
database o records or n-ary relation
– 5he relation is R(3tudent-,a"e+ Id-nu"ber+
aDor+ E%A)
2
-
8/9/2019 210-ch8-part1
23/34
2
,-ary Relations & their Applications (8.2) (cont.)
– a"ple o records
(3"ith+ 721+ athe"atics+ 7.F)
(3te#ens+ 112+ Co"puter 3cience+ .)
(Rao+
-
8/9/2019 210-ch8-part1
24/34
2(
,-ary Relations & their Applications (8.2) (cont.)
Students
Names
ID # Ma!" $%
3"ith
3te#ens
Rao Ada"s
ee
721
112
-
8/9/2019 210-ch8-part1
25/34
2'
,-ary Relations & their Applications (8.2) (cont.)
Hperations on n-ary relations
– 5here are #arieties o operations that are appliedon n-ary relations in order to create ne relationsthat anser e#entual @ueries o a database
– 'einition 2:
et R be an n-ary relation and C a condition thatele"ents in R "ay satisy. 5hen the selection
operator sC "aps n-ary relation R to the n-aryrelation o all n-tuples ro" R that satisy thecondition C.
2/
-
8/9/2019 210-ch8-part1
26/34
2/
,-ary Relations & their Applications (8.2) (cont.)
– a"ple:
i sC / aDor / co"puter scienceJ ∧ E%A K
7.0J then the result o this selection consists
o the 2 our-tuples:
(3te#ens+ 112+ Co"puter 3cience+ .)
(ee+ 17+ Co"puter 3cience+ 7.G)
27
-
8/9/2019 210-ch8-part1
27/34
27
,-ary Relations & their Applications (8.2) (cont.)
– 'einition 7:
5he proDection "aps the n-tuple
(a1+ a2+ >+ an) to the "-tuplehere " ≤ n.
In other ords+ the proDectiondeletes n – " o the co"ponents o n-tuple+
lea#in! the i1th+ i2th+ >+ and i"th co"ponents.
!i ,...,"i ,#i $
)a ,...,a ,a( !i "i #i
!i ,...,"i ,#i $
-
8/9/2019 210-ch8-part1
28/34
2
-
8/9/2019 210-ch8-part1
29/34
2
,-ary Relations & their Applications (8.2) (cont.)
– 'einition :
et R be a relation o de!ree " and 3 a relation
o de!ree n. 5he Doin Lp(R+3)+ here p≤ " andp ≤ n+ is a relation o de!ree
" M n – p that consists o all (" M n – p)-tuples
(a1+ a2+ >+ a"-p+ c1+ c2+ >+ cp+ b1+ b2+ >+ bn-p)+
here the "-tuple (a1+ a2+ >+ a"-p+ c1+ c2+ >+ cp)belon!s to R and the n-tuple (c1+ c2+ >+ cp+ b1+
b2+ >+ bn-p) belon!s to 3.
0
-
8/9/2019 210-ch8-part1
30/34
0
,-ary Relations & their Applications (8.2) (cont.)
– a"ple: hat relation results hen theoperator L2 is used to co"bine the relationdisplayed in tables C and '=
1%roessor 'pt Course B
-
8/9/2019 210-ch8-part1
31/34
1%roessor 'pt Course B
CruN
CruN
4arber
4arber Era""er
Era""er
Rosen
Rosen
Ooolo!y
Ooolo!y
%sycholo!y
%sycholo!y%hysics
%hysics
Co"puter 3cience
athe"atics
770
12
01
-
8/9/2019 210-ch8-part1
32/34
2
,-ary Relations & their Applications (8.2) (cont.)
Solution: 5he Doin L2 produces the relationshon in 5able
%roessor 'pt Course B Roo" 5i"e
CruN
CruN
4arber
4arber
Era""er Rosen
Rosen
Ooolo!y
Ooolo!y
%sycholo!y
%sycholo!y
%hysicsCo"puter 3cience
athe"atics
770
12
01
-
8/9/2019 210-ch8-part1
33/34
,-ary Relations & their Applications (8.2) (cont.)
– a"ple: e ill illustrate ho 3P (3tructured Pueryan!ua!e) is used to epress @ueries by shoin! ho3P can be e"ployed to "a$e a @uery about airlineli!hts usin! 5able 4. 5he 3P state"ents
SELECT departure_time
FROM Flights
WHERE destination = ‘Detroit
are used to ind the proDection %0 (on the departureQti"e
attribute) o the selection o 0-tuples in the li!htsdatabase that satisy the condition: destination /'etroitS. 5he output ould be a list containin! the ti"eso li!hts that ha#e 'etroit as their destination+ na"ely+8:1+ 8:G+ and F:.
(
-
8/9/2019 210-ch8-part1
34/34
(
,-ary Relations & their Applications (8.2) (cont.)
Airline 4li!ht B Eate 'estination 'eparture ti"e
,adir Ac"e
Ac"e
Ac"e
,adir Ac"e
,adir
122221
122
727
1FF222
722
722
77
7
1722
7
'etroit'en#er
Anchora!e
Tonolulu
'etroit'en#er
'etroit
8:18:1G
8:22
8:7
8JGF:1
F:
able * *li6hts