DISCRETE MATHEMATICS Lecture 20 - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

DISCRETE MATHEMATICS Lecture 20

Description:

A relational database is essentially just an n-ary relation R. A domain Ai is a primary key for the database if the relation R is functional in Ai. ... – PowerPoint PPT presentation

Number of Views:483
Avg rating:3.0/5.0
Slides: 25
Provided by: Kem
Category:

less

Transcript and Presenter's Notes

Title: DISCRETE MATHEMATICS Lecture 20


1
DISCRETE MATHEMATICSLecture 20
  • Dr. Kemal Akkaya
  • Department of Computer Science

2
8.2 n-ary Relations
  • An n-ary relation R on sets A1,,An, written
    (with signature) RA1An or RA1,,An, is
    simply a subset R ? A1 An.
  • The sets Ai are called the domains of R.
  • The degree of R is n.
  • R is functional in the domain Ai if it contains
    at most one n-tuple (, ai ,) for any value ai
    within domain Ai.

3
Example
  • Let R be a relation on NxNxN consisting of
    triples (a,b,c) where a, b, c are integers with a
    lt b lt c.
  • Then (1, 2, 3) is an element of R
  • (2, 4, 3) is not
  • Let R be the relation with 5-tuples (A, N, S, D,
    T). A Airline, N flight number, S starting
    point, D destination, T departure time
  • Degree of this Relation is 5
  • Domain set of all airlines, all flight numbers,
    all cities, all cities, all times

4
Relational Databases
  • A relational database is essentially just an
    n-ary relation R.
  • A domain Ai is a primary key for the database if
    the relation R is functional in Ai.
  • Combinations of domains can also uniquely
    identify n-tuples composite key
  • A composite key for the database is a set of
    domains Ai, Aj, such that R contains at most
    1 n-tuple (,ai,,aj,) for each composite value
    (ai, aj,)?AiAj

5
Selection Operators
  • We may define operations on n-ary relations
  • Let A be any n-ary domain AA1An, and let
    CA?T,F be any condition (predicate) on
    elements (n-tuples) of A.
  • Then, the selection operator sC is the operator
    that maps any (n-ary) relation R on A to the
    n-ary relation of all n-tuples from R that
    satisfy C.
  • I.e., ?R?A, sC(R) a?R sC(a) T

6
Selection Operator Example
  • Let Rooms be the relation with attributes Place,
    Seats, BoardType, Computer A (P, S, B, C)
  • R(Fan171, 80, Chalk, Yes), (Lws210, 25, No,
    Yes), (Nek138, 50, Chalk, No), (Agr212, 200, No,
    Yes),
  • R1 select ( R, BoardType, Chalk)
  • R1(Fan171,80, Chalk, Yes), (Nek138, 50, Chalk,
    No),
  • R2 select (A, Computer, Yes)
  • select (select(R1), Computer, Yes)
  • R2 (Fan171,80, Chalk, Yes),

7
Projection Operators
  • Let A A1An be any n-ary domain, and let
    ik(i1,,im) be a sequence of indices all
    falling in the range 1 to n,
  • That is, where 1 ik n for all 1 k m.
  • Then the projection operator on n-tuplesis
    defined by

8
Projection Example
  • Let Rooms be the relation with attributes Place,
    Seats, BoardType, Computer A (P, S, B, C)
  • R(Fan171, 80, Chalk, Yes), (Lws210, 25, No,
    Yes), (Nek138, 50, Chalk, No), (Agr212, 200, No,
    Yes),
  • R1 project (R, P, S) will produce a relation
    limited to the place and number of seats.
  • R1 (Fan171, 80), (Lws210, 25), (Nek138, 50),
    (Agr212, 200),

9
Join Operator
  • Puts two relations together to form a sort of
    combined relation.
  • If the tuple (A,B) appears in R1, and the tuple
    (B,C) appears in R2, then the tuple (A,B,C)
    appears in the join J(R1,R2).
  • A, B, and C here can also be sequences of
    elements (across multiple fields), not just
    single elements.

10
Join Example
  • Suppose R1 is a teaching assignment table,
    relating Professors to Courses.
  • Suppose R2 is a room assignment table relating
    Courses to Rooms,Times.
  • Then J(R1,R2) is like your class schedule,
    listing (professor,course,room,time).

11
Join Example
  • Prof. Course
  • John CS202
  • Brian CS340
  • Kenny CS220
  • Kemal CS215
  • Course Class Time
  • CS215 FNR1326 11
  • CS220 FNR2332 9
  • CS340 Quig101 2
  • CS202 LWS202 3

R2
R1
What is the result of R1 joining R2 (J(R1, R2))?
12
Join Result
  • Prof. Course Class Time
  • Kemal CS215 FNR1326 11
  • Kenny CS220 FNR2332 9
  • Brian CS340 Quig101 2
  • John CS202 LWS202 3

13
8.3 Representing Relations
  • Some ways to represent n-ary relations
  • With an explicit list or table of its tuples.
  • With a function from the domain to T,F.
  • Or with an algorithm for computing this function.
  • Some special ways to represent binary relations
  • With a zero-one matrix.
  • With a directed graph.

14
Using Zero-One Matrices
  • To represent a binary relation RAB by an
    AB 0-1 matrix MR mij, let mij 1 iff
    (ai,bj)?R.
  • E.g., Suppose Joe likes Susan and Mary, Fred
    likes Mary, and Mark likes Sally.
  • Then the 0-1 matrix representationof the
    relationLikesBoysGirlsrelation is

15
Zero-One Reflexive, Symmetric
  • Terms Reflexive, non-reflexive,
    irreflexive,symmetric, asymmetric, and
    antisymmetric.
  • These relation characteristics are very easy to
    recognize by inspection of the zero-one matrix.

any-thing
any-thing
anything
any-thing
any-thing
Reflexiveall 1s on diagonal
Irreflexiveall 0s on diagonal
Symmetricall identicalacross diagonal
Antisymmetricall 1s are acrossfrom 0s
16
Using Directed Graphs
  • A directed graph or digraph G(VG,EG) is a set VG
    of vertices (nodes) with a set EG?VGVG of edges
    (arcs,links). Visually represented using dots
    for nodes, and arrows for edges. Notice that a
    relation RAB can be represented as a graph
    GR(VGA?B, EGR).

Edge set EG(blue arrows)
Graph rep. GR
Matrix representation MR
Joe
Susan
Fred
Mary
Mark
Sally
Node set VG(black dots)
17
Digraph Reflexive, Symmetric
  • It is extremely easy to recognize the
    reflexive/irreflexive/ symmetric/antisymmetric
    properties by graph inspection.

?
?
?
?
?
?
?
?
?
?
?
ReflexiveEvery nodehas a self-loop
IrreflexiveNo nodelinks to itself
SymmetricEvery link isbidirectional
AntisymmetricNo link isbidirectional
These are asymmetric non-antisymmetric
These are non-reflexive non-irreflexive
18
Example
  • 1 0
  • 0 1 1
  • 0 1 1

M
Reflexive?
Symmetric?
Antisymmetric?
19
Digraph Reflexive, Symmetric, Transitive
a
a
b
a
a
b
b
b
reflexive
symmetric
transitive
c
c
d
c
d
d
d
c
R(a,b),(b,c),(c,d),(d,a)
20
8.4 Closures of Relations
  • For any property X, the X closure of a set A is
    defined as the smallest superset of A that has
    the given property.
  • The reflexive closure of a relation R on A is
    obtained by adding (a,a) to R for each a?A.
    I.e., it is R ? IA
  • The symmetric closure of R is obtained by adding
    (b,a) to R for each (a,b) in R. I.e., it is R ?
    R-1
  • The transitive closure or connectivity relation
    of R is obtained by repeatedly adding (a,c) to R
    for each (a,b),(b,c) in R.
  • I.e., it is

21
8.5 Equivalence Relations
  • An equivalence relation (e.r.) on a set A is
    simply any binary relation on A that is
    reflexive, symmetric, and transitive.
  • E.g., itself is an equivalence relation.
  • For any function fA?B, the relation have the
    same f value, or f (a1,a2) f(a1)f(a2)
    is an equivalence relation,
  • e.g., let mmother of then m have the same
    mother is an e.r.

22
Equivalence Relation Examples
  • Strings a and b are the same length.
  • Integers a and b have the same absolute value.
  • Real numbers a and b have the same fractional
    part. (i.e., a - b ? Z)
  • Integers a and b have the same residue modulo
    m. (for a given mgt1)

23
8.6 Partial Orderings
  • A relation R on A is called a partial ordering or
    partial order iff it is
  • reflexive, antisymmetric, and transitive.
  • We often use a symbol looking something like ?
    (or analogous shapes) for such relations.
  • A set A together with a partial order ? on A is
    called a partially ordered set or poset and is
    denoted (A, ?).
  • Examples , on real numbers, ?, ? on sets.
  • 3 3 Reflexive
  • 3 4 but 4 is not 3 Antisymmetric
  • 3 4 and 4 5 then 3 5 Transitive

24
Total Ordering
  • Another example the divides relation on Z.
  • Note it is not necessarily the case that either
    a?b or b?a.
  • 3 9 but neither 5 7 nor 7 5
  • 3 and 9 are comparable but not 5 and 7
  • Thats why divides relation is a partial
    ordering
  • If we need a total ordering then any two elements
    of a poset (A, ?) should be comparable
  • (Z, ) is a totally ordered poset.
Write a Comment
User Comments (0)
About PowerShow.com