DM Unit 1
DM Unit 1
Relations:
The domain of R, Dom(R), is the set {x|(x,y)∈ R for some y in B}{x|(x,y)∈ RforsomeyinB}
The range of R, Ran(R), is the set {y|(x,y)∈ R for some x in A}{y|(x,y)∈ RforsomexinA}
Examples
Dom(R) = {1,3},Ran(R)={1,3}{1,3},Ran(R)={1,3}
Dom(R) = {1,2},Ran(R)={3,7}{1,2},Ran(R)={3,7}
Dom(R) = {2,9},Ran(R)={1,3,7}{2,9},Ran(R)={1,3,7}
Representation of Relations using Graph
The number of vertices in the graph is equal to the number of elements in the set from which the
relation has been defined. For each ordered pair (x, y) in the relation R, there will be a directed
edge from the vertex ‘x’ to vertex ‘y’. If there is an ordered pair (x, x), there will be self- loop
on vertex ‘x’.
Types of Relations
Alice X
Bob X X
Claire
Dan X X
1 0 0
0 1 1
MR
0 0 0
0 1 1
Closure of Relations:
The closure of a relation R with respect to property P is the relation obtained by adding the
minimum number of ordered pairs to R to obtain property P. In terms of the digraph
representation of R To find the reflexive closure - add loops. To find the symmetric closure -
add arcs in the opposite direction. To find the transitive closure - if there is a path from a to b,
add an arc from a to b.
Suppose that we have three sets A, B and C; a relation R defined from A to B, and a relation S
defined from B to C. We can now define a new relation known as the composition of R and S,
written as S ◦ R. This new relation is defined as follows. If a is an element in A and c is an
element in C, then a(S ◦ R)c if and only if there exists some element b in B, such that aRb and
bSc. This means that we have a relation S ◦ R from a to c, if and only if we can reach from a to c
in two steps; i.e. from a to b related by R and from b to c related by S. In this manner relation S ◦
R can be interpreted as R followed by S, since this is the order in which the two relations need to
be considered, first R then S.
Algorithm:
The Algorithm
WARSHALL
1. CLOSURE Ã MAT
2. for k = 1 to n
3. for i = 1 to n
4. for j = 1 to n
5. CLOSURE(i; j) Ã CLOSURE(i; j)_(CLOSURE(i; k)^CLOSURE(k; j))
MR=W0=[ ]
for k=1,1 is in the 1st and 3rd row 1st and 3rd row 1st ,2nd and 4th columns.hence put 1 in the
addtitional position(3,4) to obtain
W1=[ ]
Similarly
W2=[ ]
W3=[ ]
W4=[ ]
W0=MR
For k=1,a1 is interior vertex for the path a4 to a4 Hence W1 has 1 in position (4,4)
W1=
[ ]
W2=W1 as there is already 1 in the position (5,2) a3 is not an interior vertex for any path in R
Hence W3=W2=W1.
a4 is an interior vertex for the path a3 to a4. hence W4 has 1 in the position (3,1)
W4=
[ ]
W5=
[ ]
Example 1: The equality relation (=) on a set of numbers such as {1, 2, 3} is an equivalence
relation.
Example 2: The congruent modulo m relation on the set of integers i.e. {<a,
b>| a b (mod m)}, where m is a positive integer greater than 1, is an equivalence relation.
Note that the equivalence relation on hours on a clock is the congruent mod 12, and that
when m = 2, i.e. the congruent mod 2, all even numbers are equivalent and all odd numbers are
equivalent. Thus the set of integers are divided into two subsets: evens and odds.
Example 3: Taking this discrete structures course together this semester is another equivalence
relation.
Equivalence relations can also be represented by a digraph since they are a binary relation on a
set. For example the digraph of the equivalence relation congruent mod 3 on {0, 1, 2, 3, 4, 5 ,
6} is as shown below. It consists of three connected components.
The set of even numbers and that of odd numbers in the equivalence relation of
congruent mod 2, and the set of integers equivalent to a number between 1 and 12 in the
equivalence relation on hours in the clock example are called an equivalence class. Formally it is
defined as follows:
Definition (equivalence class): For an equivalence relation R on a set A, the set of the elements
of A that are related to an element, say a, of A is called the equivalence class of element a and it
is denoted by [a].
Example 4: For the equivalence relation of hours on a clock, equivalence classes are
where N is the set of natural numbers. There are altogether twelve of them.
Definition (partition): Let A be a set and let A1, A2, ..., An be subsets of A. Then {A1, A2,
..., An} is a partition of A, if and only if
(1) Ai = A, and
(2) Ai Aj = , if Ai Aj , 1 i, j n.
Example 5: Let A = {1, 2, 3, 4, 5}, A1 = {1, 5}, A2 = {3}, and A3 = {2, 4}.
Then {A1, A2, A3} is a partition of A. However, B1 = {1, 2, 5}, B2 = {2, 3}, and B3 = {4} do
not form a partition for A because B1 B2 , though B1 B2.
Theorem 2: Let {A1, ..., An} be a partition of a set A. Define a binary relation R on A as
The ordered pair <A, R> is called a poset (partially ordered set) when R is a partial order.
Example 1: The less-than-or-equal-to relation on the set of integers I is a partial order, and the
set I with this relation is a poset.
Example 2: The subset relation on the power set of a set, say {1, 2} , is also a partial order, and
the set {1, 2} with the subset relation is a poset.
The strictly-less-than and proper-subset relations are not partial order because they are not
reflexive. They are examples of some relation called quasi order.
Partitions of a set Let S be a set. A collection of (finitely or infinitely many) nonempty subsets
A1, A2, . . . of S is called a partition of S if it has the following properties: • No overlaps: The
sets Ai are pairwise disjoint; i.e., Ai ∩ Aj = Ǿ if i 6= j. • Union is all of S: The union of all the
sets Ai in the partition is S, i.e., A1 ∪ A2 ∪ A3 ∪ · · · = S.
Equivalence relations and partitions: The Fundamental Theorem The following fundamental
result connects the seemingly unrelated concepts of an equivalence relation on a set S (which,
formally, is a subset of S × S with certain properties) and a partition on S (which is a collection
of subsets of S with certain properties).
• From equivalence relations to partitions: Given an equivalence relation on a set S, the set of
distinct equivalence classes forms a partition of S. That is, we have: (i) For any x, y ∈ S, the
associated equivalence classes Ex and Ey are either equal (i.e., Ex = Ey) or disjoint (i.e., Ex ∩
Ey = Ǿ). (ii) For any x ∈ S there exists an equivalence class that contains x (namely, the class
Ex)
From partitions to equivalence relations: Given a partition of S into sets A1, A2, . . . , An, the
relation defined by “x <= y” ⇐⇒ “x and y belong to the same set Ai from the partition” is an
equivalence relation on S.
Hasse Diagrams
Hasse diagrams are meant to present partial order relations in equivalent but somewhat simpler
forms by removing certain deducible ``noncritical'' parts of the relations. For better motivation
and understanding, we'll introduce it through the following examples.
A={ 3, 4, 5, 6, 10, 12 }
(x, y) R iff x | y ,
i.e. (x,y) R if and only if x divides y. Give explicitly R in terms of its elements and draw the
corresponding Hasse diagram.
(b)
Let a new binary relation R' on the set A given in (a) be defined by
and R'' be the transitive closure of R'. Use directed graphs to represent R, R' and R'' respectively.
Which of the three relations R, R' and R'' is an equivalence relation? For the equivalence
relation, give all the distinct equivalence classes.
Solution
(a)
Among all the elements of set A={ 3, 4, 5, 6, 10, 12 }, obviously 3 A, for instance,
divides 3, 6 and 12. Hence by the definition of the relation R specified by the question we
conclude (3,3), (3,6)and (3,12) are all elements of the relation R. Likewise we can show
that (4,4), (4,12), (5,5), (5,10), (6,6), (6,12), (10,10), (12,12) are all elements of R. In fact we
have
R = { (3,3), (3,6), (3,12), (4,4), (4,12), (5,5), (5,10), (6,6), (6,12), (10,10), (12,12) } .
(b)
The digraphs for R is already given in (a). As for R' we observe that, according to the definition
of the relation R', if (x,y) (e.g. (3,6) ) is in R so will (y,x) (thus e.g. (6,3) ). Hence we can
obtain R'by adding to R the symmetric pairs like (6,3), (12,3) etc. In terms of the digraph, such
addition of elements is equivalent to drawing an opposite arrows to each existing (non-loop)
arrows. The digraph of R' thus takes the following form
Since relation R'' is the transitive closure of R', we can derive R'' from R' by connecting 3 to 4
and 4 to 6 and connecting 4 to 3 and 6 to 4. We connect 3 to 4 via an direct arrow because we
can travel from 3 to 12 and then from 12 to 4 all along the arrows, and we connect 4 to 3
because we can travel from 4 to 12 then to 3 all along the arrows too. Similar reasons are
applicable for the arrows from 4 to 6 and 6 to 4. Hence R'' can be drawn as
Since there is no arrow from element 12 to element 3 in the digraph of R despite the existence of
an arrow from 3 to 12, relation R is not symmetric hence is not an equivalence relation. Since
relation R' is not transitive (because its transitive closure R'' is not the same as R' itself),
relation R' is not an equivalence relation either. As for the relation R'' , it is obviously reflexive,
symmetric and transitive. Hence R'' is an equivalence relation.
Since elements 3, 4, 6 and 12 are all related (connected) to each other through the arrows of the
digraph R'' and none of these 4 elements are related to any other elements, they must form a
single equivalence class. Hence we have
[3] = { 3, 4, 6, 12 } .
[5] = { 5, 10 } .
Because any element of A is either in the equivalence class [3] or in the equivalence class [5],
these two classes are all the distinct equivalence classes.
Lattice:
A special structure arises when every pair of elements in a poset has an lub and a glb •
Definition: A lattice is a partially ordered set in which every pair of elements has both – a least
upper bound and – a greatest lower bound
A lattice is a poset in (L,≤) in which every subset {a,b} consisiting of two elements has a least
upper bound and a greatest lower bound. LUB({a,b}) is denoted by a v b and is called the join of
a and b. GLB({a,b}) is denoted by a Λ b and is called the meet of a and b.
Chains & Antichains
Let (A,≤) be a poset .A subset A is called chain if every pair in the subset is related.
Example:
Let A= {1,2,3} and let the poset ≤ mean less than or equal to. The chain is represented as
Antichain:
Keys:
Each row in a table has its own unique key. Rows in a table can be linked to rows in other tables
by adding a column for the unique key of the linked row (such columns are known as foreign
keys). Codd showed that data relationships of arbitrary complexity can be represented by a
simple set of concepts.
Below is an example of a relation having three named attributes: 'ID' from the domain
of integers, and 'Name' and 'Address' from the domain of strings:
A predicate for this relation, using the attribute names to denote free variables, might be
"Employee number ID is known as Name and lives at Address". Examination of the relation
tells us that there are just four tuples for which the predicate holds true. So, for example,
employee 102 is known only by that name, Yonezawa Akinori, and does not live anywhere else
but in Naha, Okinawa. Also, apart from the four employees shown, there is no other employee
who has both a name and an address.
Under the definition of body, the tuples of a body do not appear in any particular order - one
cannot say "The tuple of 'Murata Makoto' is above the tuple of 'Matsumoto Yukihiro'", nor can
one say "The tuple of 'Yonezawa Akinori' is the first tuple." A similar comment applies to the
rows of an SQL table.
Relational Operator:
Relational Database posses well defined operators that act on relations.There are three operators
Slection,Projection and Join.
Selection: Given a relational database user may be intrested in only some of the vallues of an
attribute.For example while considering the performance report of a group of students, we wish
to focus only on these students whose performance is below certain level(below 50%).
Example:
ALKA 105 A 67
BHARAT 125 A 40
TARUN 232 B 72
BHAVANA 312 C 48
KALPESH 453 D 40
ROHIT 526 E 74
BHARAT 125 A 40
BHAVANA 312 C 48
KALPESH 453 D 40
Projection: Using the operation we can extract necessary attributes from the database table
CLARA 101 B IT 90
Suppose we are intrested only in the information relating to the student and marks then we will
get to the projection table
Name Percentage
ASHWIN 87
CLARA 90
LOKESH 75
PRIYA 67
Join: If R and S represent two relational databases then RXS is the join of R and S
R
Name Roll No
ASHWIN 100
CLARA 101
LOKESH 102
PRIYA 103
Name Percentage
ASHWIN 87
CLARA 90
LOKESH 75
PRIYA 67
Join of R and S is
ASHWIN 100 87
CLARA 101 90
LOKESH 102 75
PRIYA 103 67
Functions:
For an example of a function, let X be the set consisting of four shapes: a red triangle, a yellow
rectangle, a green hexagon, and a red square; and let Y be the set consisting of five colors: red,
blue, green, pink, and yellow. Linking each shape to its color is a function from X to Y: each
shape is linked to a color (i.e., an element in Y), and each shape is "linked", or "mapped", to
exactly one color. There is no shape that lacks a color and no shape that has more than one color.
This function will be referred to as the "color-of-the-shape function".
The input to a function is called the argument and the output is called the value. The set of all
permitted inputs to a given function is called the domain of the function, while the set of
permissible outputs is called the codomain. Thus, the domain of the "color-of-the-shape
function" is the set of the four shapes, and the codomain consists of the five colors. The concept
of a function does not require that every possible output is the value of some argument, e.g. the
color blue is not the color of any of the four shapes in X.
A second example of a function is the following: the domain is chosen to be the set of natural
numbers (1, 2, 3, 4, ...), and the codomain is the set of integers (..., −3, −2, −1, 0, 1, 2, 3, ...). The
function associates to any natural number n the number 4−n. For example, to 1 it associates 3
and to 10 it associates −6.
Notation
A function f is commonly declared by stating its domain X and codomain Y using the
expression
f: x y
in this context, the elements of X are called arguments of f. For each argument x, the
corresponding unique y in the codomain is called the function value at x or
the image of x under f. It is written as f(x). One says that f associates y with x or maps x to y.
This is abbreviated by
y=f(x)
Graphical representation of functions.
The above diagram represents a function with domain {1, 2, 3}, codomain {A, B, C, D} and set
of ordered pairs {(1,D), (2,C), (3,C)}. The image is {C,D}.
1.One to one function(Injective): A function is called one to one function if for all elements of a
and b in A such that f(a) = f(b), i.e. a = b. It never maps distinct elements of its domain to the
same element of its co-domain.
4.Inverse Functions:Bijection function are also known as invertible function because they
have inverse function property. The inverse of bijection f is denoted as f-1. It is a function
which assigns to b, a unique element a such that f(a) = b. hence f-1 (b) = a.
Composite Functions
Composition of functions is when one function is inside of another function. For example, if
we look at the function h(x) = (2x – 1)2 . We can say that this function, h(x), was formed by
the composition of two other functions, the inside function and the outside function. In
the case of h(x) = (2x – 1)2 , the inside function is 2x – 1 and the outside function is z 2 ,
the letter z was used just to represent a different variable, we could have used any letter
that we wanted. Notice that if we put the inside function, 2x – 1, into the outside function,
z 2 , we would get z 2 = (2x – 1)2 , which is our original function h(x)
The notation used for the composition of functions looks like this, (f o g)(x). So what does
this mean (f o g)(x), the composition of the function f with g is defined as follows: (f og)(x)
= f(g(x)), notice that in the case the function g is inside of the function f. In
composite functions it is very important that we pay close attention to the order in which
the composition of the functions is written. In many cases (f og)(x) is not the same as (g
of)(x). Let’s look at why the order is so important: (f og)(x) = f(g(x)), the g function is
inside of the f function (g of )(x) = g(f(x)), the f function is inside of the g function (f og)(x)
and (g of )(x) are often different because in the composite (f o g)(x), f(x) is
the outside function and g(x) is the inside function. Whereas in the composite (g of)(x), g(x)
is the outside function and f(x) is the inside function. This difference in order will often
be the reason why we will get different answers for (f og)(x) and (g of)(x). This means we
need to make sure that we pay close attention to the way the problem is written when
we are trying to find the composition of two functions.
Example 1: If f(x) = –4x + 9 and g(x) = 2x – 7, find (f o g)(x).
(f o g)(x) = f(g(x)) = -4(2x - 7) + 9 = -8x+28+7= -8x+37
Pigeonhole Principle
In mathematics, the pigeonhole principle states that if n items are put into m containers,
with n > m, then at least one container must contain more than one item.This theorem is
exemplified in real life by truisms like "in any group of three gloves there must be at least two
left gloves or two right gloves".
Examples
The birthday problem asks, for a set of n randomly chosen people, what is the probability that
some pair of them will have the same birthday? By the pigeonhole principle, if there are 367
people in the room, we know that there is at least one pair who share the same birthday, as there
are only 366 possible birthdays to choose from (including February 29, if present). The birthday
"paradox" refers to the result that even if the group is as small as 23 individuals, there will still
be a pair of people with the same birthday with a 50% probability. While at first glance this may
seem surprising, it intuitively makes sense when considering that a comparison will actually be
made between every possible pair of people rather than fixing one individual and comparing
them solely to the rest of the group.
Softball team
Imagine seven people who want to play softball (n = 7 items), with a limitation of only four
softball teams (m = 4 holes) to choose from. The pigeonhole principle tells us that they cannot all
play for different teams; there must be at least one team featuring at least two of the seven
players:
Subset sum
Any subset of size six from the set S = {1,2,3,...,9} must contain two elements whose sum is 10.
The pigeonholes will be labelled by the two element subsets {1,9}, {2,8}, {3,7}, {4,6} and the
singleton {5}, five pigeonholes in all. When the six "pigeons" (elements of the size six subset)
are placed into these pigeonholes, each pigeon going into the pigeonhole that has it contained in
its label, at least one of the pigeonholes labelled with a two element subset will have two pigeons
in it.
Types of Sets:
A countable set is a set with the same cardinality (number of elements) as some subset of the set
of natural numbers. A countable set is either a finite set or a countably infinite set. Whether finite
or infinite, the elements of a countable set can always be counted one at a time and, although the
counting may never finish, every element of the set is associated with a unique natural number.
A set S is countable if there exists an injective function f from S to the natural numbers
N = {0, 1, 2, 3, ...}.
If such an f can be found that is also surjective (and therefore bijective), then S is
called countably infinite.
In other words, a set is countably infinite if it has one-to-one correspondence with the natural
number set, N
Uncountable sets
An uncountable set (or uncountably infinite set) is an infinite set that contains too
many elements to be countable. The uncountability of a set is closely related to its cardinal
number: a set is uncountable if its cardinal number is larger than that of the set of all natural
numbers.
X is nonempty and for every ω-sequence of elements of X, there exist at least one element of X
not included in it. That is, X is nonempty and there is no surjective function from the natural
numbers to X.
The cardinality of X is neither finite nor equal to (aleph-null, the cardinality of the natural
numbers).
Infinite Sets
In set theory, an infinite set is a set that is not a finite set. Infinite sets may
be countable or uncountable. Some examples are:
the set of all integers, {..., -1, 0, 1, 2, ...}, is a countably infinite set; and
The set of natural numbers (whose existence is postulated by the axiom of infinity) is infinite. It
is the only set that is directly required by the axioms to be infinite. The existence of any other
infinite set can be proved in Zermelo–Fraenkel set theory (ZFC) only by showing that it follows
from the existence of the natural numbers.
A set is infinite if and only if for every natural number the set has a subset whose cardinality is
that natural number.
If the axiom of choice holds, then a set is infinite if and only if it includes a countable infinite
subset.
If a set of sets is infinite or contains an infinite element, then its union is infinite. The powerset
of an infinite set is infinite. Any superset of an infinite set is infinite. If an infinite set is
partitioned into finitely many subsets, then at least one of them must be infinite. Any set which
can be mapped onto an infinite set is infinite. The Cartesian product of an infinite set and a
nonempty set is infinite. The Cartesian product of an infinite number of sets each containing at
least two elements is either empty or infinite; if the axiom of choice holds, then it is infinite.
Finite Set
A finite set is a set that has a finite number of elements. Informally, a finite set is a set which one
could in principle count and finish counting. For example,
A={0,1,2,3,4}
is a finite set with five elements. The number of elements of a finite set is a natural
number (a non-negative integer) and is called the cardinality of the set. A set that is not finite is
called infinite. For example, the set of all positive integers is infinite: countably infinite and
uncountable infinite sets
A countable set is a set with the same cardinality (number of elements) as some subset of the set
of natural numbers. A countable set is either a finite set or a countably infinite set. Whether finite
or infinite, the elements of a countable set can always be counted one at a time and, although the
counting may never finish, every element of the set is associated with a unique natural number.
Some authors use countable set to mean countably infinite alone. To avoid this ambiguity, the
term at most countable may be used when finite sets are included and countably
infinite, enumerable,or denumerable] otherwise.
A set S is countable if there exists an injective function f from S to the natural numbers N = {0,
1, 2, 3, ...}
If such an f can be found that is also surjective (and therefore bijective), then S is
called countably infinite.
In other words, a set is countably infinite if it has one-to-one correspondence with the natural
number set, N.
An infinite set, such as the real numbers, which is not countably infinite.
It might seem natural to divide the sets into different classes: put all the sets containing one
element together; all the sets containing two elements together; ...; finally, put together all
infinite sets and consider them as having the same size. This view is not tenable, however, under
the natural definition of size.
To elaborate this we need the concept of a bijection. Although a "bijection" seems a more
advanced concept than a number, the usual development of mathematics in terms of set theory
defines functions before numbers, as they are based on much simpler sets. This is where the
concept of a bijection comes in: define the correspondence
a ↔ 1, b ↔ 2, c ↔ 3
Since every element of {a, b, c} is paired with precisely one element of {1, 2, 3}, and vice versa,
this defines a bijection.
We now generalize this situation and define two sets as of the same size if (and only if) there is a
bijection between them. For all finite sets this gives us the usual definition of "the same size".
What does it tell us about the size of infinite sets?
Consider the sets A = {1, 2, 3, ... }, the set of positive integers and B = {2, 4, 6, ... }, the set of
even positive integers. We claim that, under our definition, these sets have the same size, and
that therefore B is countably infinite. Recall that to prove this we need to exhibit a bijection
between them. But this is easy, using n ↔ 2n, so that
1 ↔ 2, 2 ↔ 4, 3 ↔ 6, 4 ↔ 8, ....
As in the earlier example, every element of A has been paired off with precisely one element of
B, and vice versa. Hence they have the same size. This is an example of a set of the same size as
one of its proper subsets, which is impossible for finite sets.
Likewise, the set of all ordered pairs of natural numbers is countably infinite, as can be seen by
following a path like the one in the picture:
The Cantor pairing function assigns one natural number to each pair of natural numbers
Interestingly: if you treat each pair as being the numerator and denominator of a vulgar fraction,
then for every positive fraction, we can come up with a distinct number corresponding to it. This
representation includes also the natural numbers, since every natural number is also a
fraction N/1. So we can conclude that there are exactly as many positive rational numbers as
there are positive integers