0% found this document useful (0 votes)
35 views

Lecture 7

The document discusses different types of relations including: 1) Composite relations which combine two relations R and S to form a new relation R o S. 2) Power relations which take a relation R and apply it to itself multiple times to form R^n. 3) Closures which minimally add elements to a relation to satisfy a property like reflexivity or symmetry. 4) Equivalence relations which are reflexive, symmetric, and transitive relations that partition a set into equivalence classes.

Uploaded by

Arif Imran
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Lecture 7

The document discusses different types of relations including: 1) Composite relations which combine two relations R and S to form a new relation R o S. 2) Power relations which take a relation R and apply it to itself multiple times to form R^n. 3) Closures which minimally add elements to a relation to satisfy a property like reflexivity or symmetry. 4) Equivalence relations which are reflexive, symmetric, and transitive relations that partition a set into equivalence classes.

Uploaded by

Arif Imran
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

Relations

1
Composite relation: R  S
Let A,B,C be sets and let R be a relation from A to B and let
S be a relation from B to C. Then R and S give rise to a
relation from A to C denoted by
a ( R  S )c if for some b  B we have (a,b) R and (b,c) S

Example:
R  {(1,1), (1,4), (2,3), (3,1), (3,4)}
S  {(1,0), (2,0), (3,1), (3,2), (4,1)}
S  R  {(1,0), (1,1), (2,1), (2,2), (3,0), (3,1)}

2
n
Power of relation: R
1 n 1 n
R R R  R R

Example: R  {(1,1), (2,1), (3,2), (4,3)}


2
R  R  R  {(1,1), (2,1), (3,1)(4,2)}
3 2
R  R  R  {(1,1), (2,1), (3,1)(4,1)}
4 3 3
R  R R  R 3
Closure
• Closure means adding something until done.
– Normally adding as little as possible until some
condition is satisfied

• Closure of relation properties


– When a property does not hold for a relation,
how could we minimally augment the relation so
that the property would hold?

4
Reflexive Closure
• Example: Consider the relation
R = {(1,1), (1,2), (2,1), (3,2)} on set {1,2,3}
– Is it reflexive?

5
Reflexive Closure – cont.
• When a relation R on a set A is not reflexive:
• The reflexive closure of R can be formed by adding all of the
pairs of the form (a,a) to R. In other words we should find:

R    R  {(a, a ) | a  A}

R = { (1,1), (1,2), (2,1), (3,2) } U { (1,1), (2,2), (3,3) }

6
Reflexive Closure – Cont.
• The diagonal relation on A is:
 = {(a,a) | a  A}.
• The reflexive closure of R is then:
R  .

1 2 3 1 2 3

1 1 1 0 1 1 1 0
R= R =(r)
2 1 0 0 2 1 1 0
3 0 1 0 3 0 1 1

a (aRa)
R = { (1,1), (1,2), (2,1), (3,2) } U { (1,1), (2,2), (3,3) }
7
Symmetric Closure (optional)
• Example: Consider
R ={(1,1), (1,2), (2,2), (2,3), (3,1), (3,2)}
– R is not symmetric; the pairs missing are:
(2,1), (1,3).
– If we add those, we obtain the new relation:
{(1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1), (3,2)}.
The new relation is symmetric.

8
Symmetric Closure (optional)
• When a relation R on a set A is not symmetric:
• The inverse of R is:
R-1 = {(b,a) | (a, b)  R}.
• The symmetric closure of R is then:
R  R-1.
1 2 3 1 2 3 1 2 3

1 1 1 0 1 1 0 1 1 1 1 1
R= R =
-1
RR =-1
2 0 1 1 2 1 1 1 2 1 1 1
3 1 1 0 3 0 1 0 3 1 1 0

ab (aRb  bRa)


{(1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1), (3,2)}
9
Transitive Closures
• Consider R = {(1,3), (1,4), (2,1), (3,2)}.
– R is not transitive;
– What are the missing terms?
• Few are: (1,2), (2,3), (2,4), (3,1).
– If we add those, we obtain the new relation:
{(1,2), (1,3), (1,4), (2,1), (2,3), (2,4), (3,1), (3,2)}.
– Is the above relation transitive?
– No, it is not. Missing terms such as (1,1), (2,2)…
 Transitive closure is more complicated to build.
10
Paths in Directed Graphs
• Definition: A path from a to b in a digraph G is
a sequence of 1 or more adjacent arcs
(a,x1), (x1,x2), (x2,x3), …, (xn-1, b).
– Denoted: a, x1, x2, x3, …, xn-1, b
– Has length n.
– If a = b, the path is called a circuit or a cycle, since
the path returns to its start.

11
Example

• R = {(1,3), (1,4), (2,1), (3,2)}.


1 2 •  a path of length 2 from 1 to 2:
arcs (1,3), (3,2).
•  a path of length 3 from 3 to 4:
(3,2), (2,1), (1,4).
• There are no paths from
– 4 to 1
4 3 – 4 to 2
– 4 to 3

12
Paths in Relations
• There is a path from a to b in R if there is a sequence
of elements: x1, x2, …, xn-1 with (a,x1)R, (x1,x2)R, …,
(xn-1, b)R.
• Example. R = {(1,3), (1,4), (2,1), (3,2)}
–  a path in R (len. 2) from 1 to 2: (1,3), (3,2)R.
–  a path in R (len. 3) from 3 to 4: (3,2), (2,1), (1,4)R.
– There is no path in R from 4 to 1, nor to 2, nor to 3.

13
Transitive Closure
• Definition: Let R be a relation on a set A.
The connectivity relation is the relation R*
defined as:
R* ={(a,b) |  a path in R from a to b}.
• From the above definition of R* we can write
as:
R* = k=1 Rk.
• R(t) = R  R2  R3  …  R|A|. (No path can be
longer than |A|, the number of elements in A.)
14
Transitive Closure – Example 1
1 2 3

1 0 1 0 1 All paths of
R= length 1
2 0 0 1
3 1 1 1 2 3
1 2 3

1 0 0 1 1 All paths of
R =
2
2 1 1 1 length 2
3 1 1 1
2 3
1 2 3

1 1 1 1
1 All paths of
R×R = R =
2 3
2 1 1 1
length 3
3 1 1 1
2 3
1 2 3

1 1 1 1
RR R =
2 3
2 1 1 1
3 1 1 1
15
Transitive Closure – Example 2
1 2 3

1 0 0 0 1
R= All paths of
2 0 0 1
length 1
3 0 1 0 2 3
1 2 3

1 0 0 0 1
R = 2
All paths of
2 0 1 0
length 2
3 0 0 1 2 3
1 2 3

1 0 0 0 1
R×R = R =
2 3
2 0 0 1 All paths of
0 1 0 length 3
3 2 3
1 2 3

1 0 0 0 1
RR R =
2 3
2 0 1 1 Paths of
any length
3 0 1 1 2 3
16
Equivalence Relations
A relation R on a set A is an equivalence relation if R is
reflexive, symmetric, and transitive.
– Equivalence relations are about “equivalence”
– Examples:
• = for integers x=x reflexive
x=yy=x symmetric
x=y  y=z  x=z transitive
• = for sets A=A reflexive
A=BB=A symmetric
A=B  B=C  A=C transitive
• Let R be “has same major as” for college students
xRx  reflexive: same major as self
xRy  yRx  symmetric: same major as each other
xRy  yRz  xRz  transitive: same as, same as
same as
Partitions
• DEFINITION: PARTITION OF A SET It is a collection of
nonempty disjoint subsets of S whose union equals S.

• A partition of a set S is
– a set of subsets Si=1,2,…n of S
– such that ni=1 Si = S, Sj  Sk =  for j  k.
• Each Si is called a block (also called an equivalence class)
• Example:
– Suppose we form teams (e.g. for a doubles tennis
tournament) from the set:
{Abe, Kay, Jim, Nan, Pat, Zed}
then teams could be: { {Abe, Nan}, {Kay, Jim}, {Pat, Zed} }
Partitions (continued…)
• Since individual elements can only appear in one
block (Sj  Sk =  for j  k), blocks can be
represented by any element within the block.
e.g. Nan’s Team
Jimmer’s 2011 sweet-16 team
• Formally, [x] = set of all elements related to x and y
 [x] iff xRy
e.g. [Nan] represents {Abe, Nan}, Nan’s team
[Abe] represents {Abe, Nan}, Abe’s team
[Jimmer] represents the set of players
who played on BYU’s 2011 sweet-16 team
n-ary Relations
• By an n- ary relation, we mean a set of ordered n-
tuples.
• For nay set S, a subset of the product set Sn is called
n-ary relation on S.
• An n-ary relation R on sets A1,…,An,
written (with signature) R:A1×…×An or R:A1,…,An, is
simply a subset
R  A1× … × An.
• The sets Ai are called the domains of R.
• The degree of R is n.
20
Relational data model
n-ary relation R is represented with table

fields
R: Teaching assignments
Professor Department Course-number
records Cruz Zoology 335
Cruz Zoology 412
Farber Psychology 501
Farber Psychology 617
Rosen Comp. Science 518
Rosen Mathematics 575

primary key
(all entries are different)
Konstantin Busch - LSU 21
Relational Model for Databases
• A database is a collection of records manipulated by
computers.
• Database Management Systems (DBMS) are programs that
help users access the information in databases.
• The primary key of a relational table uniquely identifies each
record in the table.
• A DBMS responds to user’s request called as queries i.e. a
query is a request for information from databases.

22
Selection operator:
Selection (  ) Selects a subset of rows from
relation i.e. selects rows that satisfy selection
condition (C).

Example: C : Department  Psychology

Result of selection operator


Professor Department Course-number
Farber Psychology 501
Farber Psychology 617

Konstantin Busch - LSU 23


Projection operator:
Projection (  ) Deletes unwanted columns from relation.

Example: PProfessor, Department ( R )


Professor Department
Cruz Zoology
Farber Psychology
Rosen Comp. Science
Rosen Mathematics

Konstantin Busch - LSU 24


Join operator: J k ( R, S )

A JOIN is a means for combining fields from


two tables R and S (or more) by using values
common to each. In this example, the lastk
fields of R are the same with the first k
fields of S

Konstantin Busch - LSU 25


S: Class schedule
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

Konstantin Busch - LSU 26


J2(R,S)
Professor Department Course Room Time
Number

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

Konstantin Busch - LSU 27

You might also like