UNIVERSITY OF DAR ES SALAAM
COLLEGE OF ICT
IS 143
Discrete Structure
Lecture 4
Instructor
Dr. Joseph Cosmas
Kijitonyama Campus
Block A,
Room No. A023
Joseph.cosmas@udsm.ac.tz
Content
Introduction to Course
Proposition, Sets, Relations and Functions
Algorithm and Basic Logics
Proof Techniques
Basics Of Counting (Mathematical Reasoning)
Graphs And Trees
Discrete Probability
Relations
Relations & their properties
Definition 1
Let A and B be sets. A binary relation from A to B is a subset
of A * B.
In other words, a binary relation from A to B is a set R of
ordered pairs where the first element of each ordered pair
comes from A and the second element comes from B.
Relations (cont.)
Notation:
aRb (a, b) R
aRb (a, b) R
0
R a b
a
1 0 X X
1 X
b
2 2 X
Relations (cont.)
Relations on a set
Definition 2
A relation on the set A is a relation from A to A.
Example:A = set {1, 2, 3, 4}. Which ordered pairs are in the
relation R = {(a, b) | a divides b}
Solution: Since (a, b) is in R if and only if a and b are positive
integers not exceeding 4 such that a divides b
R = {(1,1), (1,2), (1.3), (1.4), (2,2), (2,4), (3,3), (4,4)}
Relations (cont.)
Properties of Relations
Definition 3
A relation R on a set A is called reflexive if
(a, a) R for every element a A.
Relations (cont.)
Example (a): Consider the following relations on {1, 2, 3, 4}
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), (3,4), (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)}
Which of these relations are reflexive?
Relations (cont.)
Solution:
R3 and R5: reflexive both contain all pairs of the form (a, a):
(1,1), (2,2), (3,3) & (4,4).
R1, R2, R4 and R6: not reflexive not contain all of these
ordered pairs. (3,3) is not in any of these relations.
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), (3,4), (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)}
Relations (cont.)
Definition 4:
A relation R on a set A is called symmetric if (b, a) R
whenever (a, b) R, for all a, b A.
A relation R on a set A such that (a, b) R and (b, a) R only
if a = b, for all a, b A, is called antisymmetric.
Relations (7.1) (cont.)
Example:Which of the relations from example (a) are symmetric and
which are antisymmetric?
Solution:
R2 & R3: symmetric each case (b, a) belongs to the relation
whenever (a, b) does.
For R2: only thing to check that both (1,2) & (2,1) belong to the relation
For R3: it is necessary to check that both (1,2) & (2,1) belong to the
relation.
None of the other relations is symmetric: find 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)}
11
Relations (cont.)
Solution (cont.):
R4, R5 and R6: antisymmetric for each of these
relations there is no pair of elements a and b with
a b such that both (a, b) and (b, a) belong to the relation.
None of the other relations is antisymmetric.: find a pair (a,
b) with a b so that (a, b) and (b, a) are both in the
relation.
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), (3,4), (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)}
Relations (cont.)
Definition 5:
A relation R on a set A is called transitive if whenever
(a, b) R and (b,c) R, then (a, c) R, for all a, b, c R.
Relations (cont.)
Example:Which of the relations in example (a) are transitive?
R4 , R5 & R6 : transitive verify that if (a, b) and (b, c) belong to this
relation then (a, c) belongs also to the relation
R4 transitive since (3,2) and (2,1), (4,2) and (2,1), (4,3) and (3,1), and (4,3)
and (3,2) are the only such sets of pairs, and (3,1) , (4,1) and (4,2) belong to
R4 .
Same reasoning for R5 and R6.
R1 : not transitive (3,4) and (4,1) belong to R1, but (3,1) does not.
R2 : not transitive (2,1) and (1,2) belong to R2, but (2,2) does not.
R3 : not transitive (4,1) and (1,2) belong to R3, but (4,2) does 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), (3,4), (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)}
Relations (cont.)
Combining relations
Example:
Let A = {1, 2, 3} and B = {1, 2, 3, 4, }.
The relations
R1 = {(1,1), (2,2), (3,3)} and
R2 = {(1,1), (1,2), (1,3), (1,4)}
can be combined to obtain:
R1 R2 = {(1,1), (1,2), (1,3), (1,4), (2,2), (3,3)}
R1 R2 = {(1,1)}
R1 – R2 = {(2,2), (3,3)}
R2 – R1 = {(1,2), (1,3), (1,4)}
Relations (cont.)
Definition 6:
Let R be a relation from a set A to a set B and S a relation
from B to a set C.
The composite of R and S is the relation consisting of ordered
pairs (a, c), where a A, c C, and for which there exists an
element b B such that (a, b) R and (b, c) S. We denote
the composite of R and S by S R.
Relations (cont.)
Example:What is the composite of the relations R and S
where R is the relation from {1,2,3} to {1,2,3,4} with R =
{(1,1), (1,4), (2,3), (3,1), (3,4)} and S is the relation from
{1,2,3,4} to {0,1,2} with S = {(1,0), (2,0), (3,1), (3,2), (4,1)}?
Solution: S R is constructed using all ordered pairs in R and
ordered pairs in S, where the second element of the
ordered in R agrees with the first element of the ordered
pair in S.
For example, the ordered pairs (2,3) in R and (3,1) in S
produce the ordered pair (2,1) in S R. Computing all the
ordered pairs in the composite, we find
S R = ((1,0), (1,1), (2,1), (2,2), (3,0), (3,1)}
N-ary Relations & their Applications
Relationship among elements of more than 2 sets often
arise: n-ary relations
Like relationship between (Airline, flight number, starting
point, destination, departure time, arrival time)
N-ary Relations & their Applications (cont.)
N-ary relations
Definition 1:
Let A1, A2, …, An be sets. An n-ary relation on these sets is a
subset of A1 * A2 *…* An where Ai are the domains of the
relation, and n is called its degree.
Example: Let R be the relation on N * N * N consisting of
triples (a, b, c) where a, b, and c are integers with a<b<c.
Then (1,2,3) R, but (2,4,3) R.
The degree of this relation is 3. Its domains are equal to the
set of integers.
N-ary Relations & their Applications (cont.)
Databases & Relations
Relational database model has been developed for information
processing
A database consists of records, which are n-tuples made up of
fields
The fields contains information such as:
Name
Student #
Major
Grade point average of the student
N-ary Relations & their Applications (cont.)
The relational database model represents a database of
records or n-ary relation
The relation is R(Student-Name, Id-number, Major, GPA)
N-ary Relations & their Applications (cont.)
Example of records
(Smith, 3214, Mathematics, 3.9)
(Stevens, 1412, Computer Science, 4.0)
(Rao, 6633, Physics, 3.5)
(Adams, 1320, Biology, 3.0)
(Lee, 1030, Computer Science, 3.7)
N-ary Relations & their Applications (cont.)
TABLE A: Students
Students ID # Major GPA
Names
Smith 3214 Mathematics 3.9
Stevens 1412 Computer Science 4.0
Rao 6633 Physics 3.5
Adams 1320 Biology 3.0
Lee 1030 Computer Science 3.7
N-ary Relations & their Applications (cont.)
Operations on n-ary relations
There are varieties of operations that are applied on n-ary
relations in order to create new relations that answer
eventual queries of a database
Definition 2:
Let R be an n-ary relation and C a condition that elements in
R may satisfy. Then the selection operator sC maps n-ary
relation R to the n-ary relation of all n-tuples from R that
satisfy the condition C.
N-ary Relations & their Applications (cont.)
Example:
if sC = “Major = “computer science” GPA > 3.5” then the
result of this selection consists of the 2 four-tuples:
(Stevens, 1412, Computer Science, 4.0)
(Lee, 1030, Computer Science, 3.7)
N-ary Relations & their Applications (cont.)
Definition 3:
The projection Pi1 ,i2 ,...,im maps the n-tuple (a1,a2, …, an) to
the m-tuple ( ai1 , ai2 ,..., aim ) where m n.
In other words, the projection Pi1 ,i 2 ,...,im deletes n – m of
the components of n-tuple, leaving the i1th, i2th, …, and imth
components.
N-ary Relations & their Applications (cont.)
Example:What relation results when the projection P1,4 is
applied to the relation in Table A?
Solution: When the projection P1,4 is used, the second and third columns
of the table are deleted, and pairs representing student names and GPA
are obtained. Table B displays the results of this projection.
Students GPA
Names
Smith 3.9
TABLE B: Stevens 4.0
GPAs Rao 3.5
Adams 3.0
Lee 3.7
N-ary Relations & their Applications (cont.)
Definition 4:
Let R be a relation of degree m and S a relation of degree n. The
join Jp(R,S), where p m and p n, is a relation of degree
m + n – p that consists of all (m + n – p)-tuples (a1, a2, …, am-p, c1,
c2, …, cp, b1, b2, …, bn-p), where the m-tuple (a1, a2, …, am-p, c1, c2,
…, cp) belongs to R and the n-tuple (c1, c2, …, cp, b1, b2, …, bn-p)
belongs to S.
N-ary Relations & their Applications (cont.)
Example:What relation results when the operator J2 is used to
combine the relation displayed in tables C and D?
Professor Dpt Course #
Cruz Zoology 335
Cruz Zoology 412
TABLE C: Farber Psychology 501
Teaching Farber Psychology 617
Assignments Grammer Physics 544
Grammer Physics 551
Rosen Computer Science 518
Rosen Mathematics 575
Dpt Course # Room Time
Computer Science 518 N521 2:00 PM
Mathematics 575 N502 3:00 PM
TABLE D: Mathematics 611 N521 4:00 PM
Class Physics 544 B505 4:00 PM
Schedule Psychology 501 A100 3:00 PM
Psychology 617 A110 11:00 AM
Zoology 335 A100 9:00 AM
Zoology 412 A100 8:00 AM
N-ary Relations & their Applications (cont.)
Solution: The join J2 produces the relation shown in Table E
Professor Dpt Course # Room Time
Table E: Cruz Zoology 335 A100 9:00 AM
Cruz Zoology 412 A100 8:00 AM
Teaching
Farber Psychology 501 A100 3:00 PM
Schedule
Farber Psychology 617 A110 11:00 AM
Grammer Physics 544 B505 4:00 PM
Rosen Computer Science 518 N521 2:00 PM
Rosen Mathematics 575 N502 3:00 PM
Representing Relations
Relations can be represented through matrices
1 if (ai , b j ) R
m ij
0 otherwise
Example: Suppose that the relation R on a set is
represented by the matrix:
1 1 0
M R 1 1 1 .
0 1 1
Is R reflexive, symmetric, and/or antisymmetric?
Representing Relations
Example: Suppose that the relation R on a set is
represented by the matrix:
1 1 0
M R 1 1 1 .
0 1 1
Is R reflexive, symmetric, and/or antisymmetric?
Solution:
- Since all the diagonal elements of this matrix are equal
to 1, then R is reflexive.
- Since the two side of diagonal reflect each other then R
is Symmetric
- Since MR is symmetric, R is not antisymmetric.
Representing Relations
Relations can also represented using diagraphs
Definition 1:
A directed graph, or diagraph, consists of a set V of vertices
(or nodes) together with a set E of ordered pairs of elements
of V called edges (or arcs).
The vertex a is called the initial vertex of the edge (a, b), and
the vertex b is called the terminal vertex of this edge.
Representing Relations
Example:The directed graph with vertices a, b, c and d , and
edges (a,b), (a,d), (b,b), (b,d), (c,a) and (d,b). The edge (b,b) is
called a loop.
a b
d c
Equivalence Relations
Equivalence classes
Definition 1:
Let R be an equivalence relation on a set A. The set of all
elements that are related to an element a of A is called the
equivalence class of a. The equivalence class of a with respect
to R is denoted by [a]R. When only one relation is under
consideration, we will delete the subscript R and write [a] for
this equivalence class.
Equivalence Relations
Example:What are the equivalences classes of 0 and 1
for congruence modulo 4?
Solution:
The equivalence class of 0 contains all the integers a
such that a 0 (mod 4). Hence, the equivalence class of
0 for this relation is
[0] = {…, -8, -4, 0, 4, 8, …}
The equivalence class of 1 contains all the integers a such
that a 1 (mod 4). The integers in this class are those
that have a remainder of 1 when divided by 4. Hence, the
equivalence class of 1 for this relation is
[1] = {…, -7, -3, 1, 5, 9, …}
Equivalence Relations
Equivalence classes & partitions
Theorem 1:
Let R be an equivalence relation on a set A. These
statements are equivalent:
i. aRb
ii. [a] = [b]
iii. [a] [b]
Equivalence Relations
Theorem 2:
Let R be an equivalence relation on a set S. Then the
equivalence classes of R form a partition of S. Conversely,
given a partition {Ai | i I} of the set S, there is an equivalence
relation R that has the sets Ai , i I, as its equivalence classes.
Equivalence Relations
Example: List the ordered pairs in the equivalence relation R
produced by the partition A1 = [1,2,3}, A2 = {4,5} and A3 =
{6} of S = {1,2,3,4,5,6}
Solution: The subsets in the partition are the equivalences
classes of R. The pair (a,b) R if and only if a and b are in
the same subset of the partition.
The pairs (1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1), (3,2) and
(3,3) R A1 = [1,2,3} is an equivalence class. The pairs
(4,4), (4,5), (5,4) and (5,5) R A2 = {4,5} is an
equivalence class. The pair (6,6) R {6} is an equivalence
class.
No pairs other than those listed belongs to R.
Examples
Let A = {1, 2, 3, 4, 5, 6}, construct matrix
representation of the relation R on A for the following
as:
Examples
Let A = {1, 2, 3} determine whether the relation R
whose matrix MR is given is an equivalence relation:
1 1 0
(c) M R 1 1 1 .
0 1 1
1 1 0
(d) M R 1 1 0 .
0 1 1
Examples
Determine whether the relation whose digraph is
given below is an equivalence relation.
Let A = {1, 2, 3} and R = {(1, 1), (1, 4), (4, 1), (4, 4), (2,
2), (2, 3), (3, 2), (3, 3)}. Write the Matrix of R and
sketch its graph. Determine whether R is equivalence.