Part1 0SetsandRelations
Part1 0SetsandRelations
Part1 0SetsandRelations
Discrete Mathematics
• Discussion of applications
PART 2
GRAPH THEORY
(Lý thuyết đồ thị) 11
Contents of Part 1: Combinatorial Theory
Chapter 1. Counting problem
• This is the problem aiming to answer the question: “How many ways are there that satisfy
given conditions?” The counting method is usually based on some basic principles and some
results to count simple configurations .
• Counting problems are effectively applied to evaluation tasks such as calculating the
probability of an event, calculating the complexity of an algorithm (how long the algorithm
will take to run), ....
Given N paintings in a row over a
distance of M centimeters.
Each painting i (1 ≤ i ≤ N) will be drawn
on a length of ti cm, so t1+t2+..+tn = M.
The K city's most famous artists have
been selected to do this work, each artist
will be assigned to draw at least one
painting. To facilitate the artist's work, if
someone is assigned to draw more than
one painting, the paintings must be
Street art adjacent to each other on the street art
12
Contents of Part 1: Combinatorial Theory
Chapter 1. Counting problem
• This is the problem aiming to answer the question: “How many ways are there that satisfy
given conditions?” The counting method is usually based on some basic principles and some
results to count simple configurations .
• Counting problems are effectively applied to evaluation tasks such as calculating the
probability of an event, calculating the complexity of an algorithm
Chapter 2. Existence problem
In the counting problem, configuration existence is obvious; in the existence problem, we need to
answer the question: "Is there a combinatorial configuration that satisfies given properties ?”
Chapter 3. Enumeration problem
This problem is interested in giving all the configurations that satisfy given conditions.
Chapter 4. Combinatorial optimization problem
• Unlike the enumeration problem, this problem only concerns the "best" configuration in a
certain sense.
• In the optimization problems, each configuration is assigned a numerical value (which is the
use value or the cost to construction the configuration), and the problem is that among the
configurations that satisfy the given conditions, find the configuration with the maximum or
minimum value assigned to it
Contents of Part 2: Graph Theory
• Graphs
• Degree sequence, Eulerian graphs, isomorphism
• Trees
• Matching
• Coloring
Chapter 0
sets, relations
19
1.Definitions
• We have already implicitly dealt with sets
– Integers (Z), rationals (Q), naturals (N), reals (R), etc.
• We will develop more fully
– The definitions of sets
– The properties of sets
– The operations on sets
26
1.2 Specification of set
Well-known sets in math:
• N = {0,1,2,3,...}
• Z = {...,-2,-1,0,1,2,...}
• Z+ = {1,2,3,...}
• Q = {p/q | p in Z, q in Z, q is not 0}
• R = {x | x is a real number}.
{,...} is used to indicate the the rest of the sequence once it’s clear how to
proceed
Example: {1,2,3,4,...}
32
2. Set operations
2.1 Set comparison
2.2 Venn diagram
2.3 Set operations
2.4 Partition and cover
Example 1: A = { 1, 2, 3 }, B = { 2, 3, 1 }, C = { 3 }. Then:
B = A, C A, C B.
Example 2:
?
{1, 4, 9, 16, ...} {1, 2, 3, ...} {0, 1, 2, ...}.
{1, 4, 9, 16, ...} {1, 2, 3, ...} {0, 1, 2, ...}.
Here, we could have used the proper subset symbol to link these three sets
instead.
37
2.1. Set comparison
• You may be asked to show that a set is
– a subset of,
– proper subset of, or
– equal to another set.
• To prove that A is a subset of B, use the equivalence discussed earlier
A B x(xA xB)
– To prove that A B it is enough to show that for an arbitrary
(nonspecific) element x, xA implies that x is also in B.
– Any proof method can be used.
• To prove that A is a proper subset of B (A B), you must prove
– A is a subset of B and
– x (xB) (xA)
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN 38
2.1. Set comparison
• Finally to show that two sets are equal, it is sufficient to
show independently (much like a biconditional) that
– A B and
–BA
• Logically speaking, you must show the following quantified
statements:
(x (xA xB)) (x (xB xA))
we will see an example later..
40
2.1. Set comparison
We shall sometimes use E and O to denote the sets of even and
odd integers respectively:
• E = {2n : n Z } = {...,−4,−2, 0, 2, 4, ...}
• O = {2n+1 : n Z } = {...,−3,−1, 1, 3, 5, ...}
U x y B
A
z
a C
U
A
47
Set Operators: Union
• Definition: The union of two sets A and B is the set that
contains all elements in A, B, or both. We write:
AB = { x | (x A) (x B) }
U
A B
1 2
U
A B
A =A
n
i 1 A2 … An
i=1
U
A B
𝒊
𝒊∈𝑰
A collection of sets is pairwise disjoint (or mutually disjoint) if every pair of sets in the
collection are disjoint.
Example:
A = A1 A2A3 A4
A1 = {1, 3, 5,7} ? A is not disjoint
A2 = {2, 4, 6} ? A is disjoint
A3 = {-1,-3,-5,-7} ? A is pairwise disjoint
A4 = {-2, -4, -6} ? B is not disjoint
A5 = {2} ? B is disjoint
B = A1 A2A3 A4 A5 ? B is pairwise disjoint
Set Operators: Set Difference
• Definition: The difference of two sets A and B is the set containing
those elements that are in A but not in B.
Denote: A\B or A−B
U
A B
U
A B
U A
A
A − B = {x | x A and x B} = A ∩ Bc.
U U
A A B
A
Example: M = {1, 2, 3, 4}
E1 = {{1, 2}, {3, 4}} is a partition of M
E2 = {{1, 2, 3}, {3, 4}} is not a partition of M
60
2.4. Partition and cover
Example: M= {11, 12, 13, 14}
E1 = {{11, 12}, {11, 13}, {12, 14}}
E2 = {{11, 12}, {13, 14}}
E3 = {{11, 12}, {13}}
63
3.1. Power Set
• Definition: The power set of a set A, denoted P(A), is the
set of all subsets of A.
Examples
{
Let A = { } P (A) = {}
,
Let A = {a} P (A) = {, {a}} {a}, {b}, {c},
Let A = {a, b} P(A)= {, {a}, {b}, {a, b}} {a, b}, {a, c}, {b, c},
{a, b, c}
Let A = {a, b, c} P(A) = ?
}
• Note: the empty set and the set itself are always elements
of the power set.
0 1 0 1 0 1
a {a, b}, {a, c}, {b, c},
{a, b, c}
}
3.1. Power Set
Let A = {a, b, c} and B = {a, b}. Determine whether each of the
following is true or false and give a brief justification.
1. B P (A)
2. B A
3. A P (A)
4. A P (A)
5. B P (A)
6. {{a}, B} P (A)
7. P (A)
8. P (A).
3.1. Power Set
Theorem.
For all sets A and B:
1. A B if and only if P (A) P (B).
2. P (A) ∩ P (B) = P (A ∩ B).
3. P (A) P (B) P (A B).
69
3.2 Properties of set operations
Let A, B and C be any sets. The following laws hold
Equality Name
A=A Identity laws (Đồng nhất)
AU=A
AU=U Domination laws (Trội)
A=
AA=A Idempotent laws (Lũy đẳng)
AA=A
A =U Complementation laws (Bù)
A∩ =
=U
=
Involution laws (Bù kép)
(A) A
3.2 Properties of set operations
Equality Name
AB=BA Commutative laws
AB=BA (Giao hoán)
A (B C) = (A B) C Associative laws
A (B C) = (A B) C (Kết hợp)
A (B C) = (A B) (A C) Distributive laws
A (B C) = (A B) (A C) (Phân phối)
AB A B De Morgan’s laws
AB A B (Luật De Morgan)
A ∩ (A B) = A Absorption laws
A (A ∩ B) = A.
Proving Set Equivalences
To prove set equivalence
A = B,
We could use common techniques:
1. Proof A B and B A.
2. Using definitions and equivalence of logical propositions
that define the set.
3. Use the truth table.
Proving Set Equivalences
To prove set equivalence
A = B,
We could use common techniques:
1. Proof A B and B A.
2. Using definitions and equivalence of logical propositions
that define the set.
3. Use the truth table.
Proving Set Equivalences
• Recall that to prove such identity A = B, we must show that:
1. The left-hand side is a subset of the right-hand side
2. The right-hand side is a subset of the left-hand side
3. Then conclude that the two sides are thus equal
Example: Let
– A={x |x is even}
– B={x |x is a multiple of 3}
– C={x |x is a multiple of 6}
• Show that AB=C
x ( x A x B) According
theo ®Þnh nghÜa giao
to definition of intersection
x x A x B ) theo luËttoDeMorgan
According De Morgan law
x x A x B) theo ®Þnh
According nghÜa phÇn bïdefinition
to complementation
x x A B )
According to union definition
theo ®Þnh nghÜa hîp
Proving Set Equivalences
To prove set equivalence
A = B,
We could use common techniques:
1. Proof A B and B A.
2. Using definitions and equivalence of logical propositions
that define the set.
3. Use the truth table.
Truth table
• Building tables:
– The columns correspond to set expressions.
– The rows correspond to all possible combinations of membership in the set.
• Fill in the table: Use "1" to indicate a member, "0" to indicate non-member.
• Equality is proven if two columns corresponding to two expressions on both sides are
identical.
Example 4: Proof: (AB)B = AB.
A B A B (A B ) B A B
0 0 0 0 0
0 1 1 0 0
1 0 1 1 1
1 1 1 0 0
Proving Set Equivalences
Example 5: Using the truth table, proof that
A (B C) = (A B) (A C)
01 1 0 1 01 0 0 0 1
Example:
Suppose that U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}.
Consider the subsets S, Q U.
• S = {2, 3, 5, 7, 11} 01101010001
• Q = {1, 2, 4, 11} 11010000001
84
4.1. Characteristic vector
Note that all the set operation (Union), (Intersection),
(complement) can be done by correspondently logic operation OR,
AND, NOT
89
4.2. Subset enumeration
Subset Enumeration Algorithm:
• Step k = 0, 1, ..., 2n-1: Output binary representation of the number k.
• Clearly, if we have the binary representation of the number k
(b1b2...bn) then the binary representation of the number k+1 can be
obtained by binary addition b1b2...bn to 1.
101
3) 011 {2,3}
4) 100 {1}
5) 101 {1,3} + 1
6) 110 {1,2}
7) 111 {1,2,3} 110 90
4.2. Subset enumeration
Subset Enumeration Algorithm
• Step k = 0, 1, ..., 2n-1: Output binary representation of the number k.
• Clearly, if we have the binary representation of the number k
(b1b2...bn) then the binary representation of the number k+1 can be
obtained by binary addition b1b2...bn to 1.
Algorithm: BINARY_INCREMENT(b1,b2,...,bn)
i = n;
while (n>=1) and (bi==1)
bi = 0;
i = i – 1 ;
endwhile
bi = 1;
91
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
4.1. Characteristic vector
4.2. Subset enumeration
4.3. List of elements
5. Relations
6. Functions
92
4.3. List of elements
• When the set U contain a large number of elements, but considered subset U have a
small cardinality, binary representation is not reasonable. In this case we can
represent the subset by list of all its elements.
• This list is usually implemented as the linked list structure. Each element of list is
a record that consists of two fields, one of which contains the information of the
element and the other one is a pointer to the next element:
class ListNode {
Object data ; //element information
ListNode next; //pointer to the next element
}
data1 data2 data3 data4
Example: if the ordered pair (a, b) is equal to (1, 2), then a=1, and b=2.
(1, 2) is not equal to the ordered pair (2, 1).
102
5.3. Binary Relation
Example:
– Let A be the students in a the CS major
• A = {Tan, Bob, Michel, Amy}
– Let B be the courses the department offers
• B = {CS101, CS201, CS202}
– We specify relation R = A B as the set that lists all students a A
enrolled in class b B
• R = { (Tan, CS101), (Bob, CS201), (Bob, CS202),
(Amy, CS201), (Amy, CS202) }
Tan Tan X
Bob X X
CS101
Bob Michel
Amy X X
CS201
Michel
CS202
Amy
NGUYỄN KHÁNH PHƯƠNG
Bộ môn KHMT – ĐHBK HN
Relations on a Set
• A relation on a set A is a relation from A to A.
This is a
{(2,3), (-1,5), (4,-2), (9,9), (0,-6)} relation
range = {-6,-2,3,5,9}
A ________
relation is a set of __________________.
ordered pairs (x, y)
Relation = { (3,5),(-2,4),(-3,4),(0,-4) }
range
The ________ set
is the ______ y
of ______ values.
EXAMPLE
Relation = { (3,5),(-2,4),(-3,4),(0,-4) }
-3 ____,
Domain: { ____, -2 ___,
0 ____}
3
-4 , ___,
Range: {____ 5 4
____}
2. Mapping:
Domain Range
-3 -4
-2 5
0 4
3
3. Table:
domain
range
x y
-3 4
-2 4
0 -4
3 5
Relation = { (3,5),(-2,4),(-3,4),(0,-4) }
4. Grid graph:
Relation = { (3,5),(-2,4),(-3,4),(0,-4) }
5. Binary matrix
-3 ____,
Domain a: { ____, -2 0 ____}
___, 3
-4 , ___,
Range b: {____ 5 4
____}
MR = [mij]nm of zeros and ones with n (=4) rows and m (=3)columns
1, if ai R b j
mij
0, if ai R b j
5.4. Relation representation
6. Directed graph
6
2
8
3
X -1 0 4 7
Y 3 6 -1 3
The relation’s primary key is an attribute whose value uniquely determines an element in the
relation.
In general, a primary key may consist of > 1 attribute.
What single attribute could serve as the primary key in the Teaching Assignment table?
122
5.5. Operations on relations
5. Composite Relations
Suppose R A×B and S B×C. Composite (or product) relation R S of two
relations R and S is the following
R S = {(a,c) | aRb bSc}
Example: Let A = {1, 2, 3, 4, 5}, B = {a, b, c, d}, C = {, , }. Consider the relations
R, S which are displayed in the following diagram
RS =?
We have: RS = {(1, ), (1, ), (4, ), (4, ), (5, ), (5, )} A×C 123
Example
• Let S be a set of students:
{ Bill, Jill, Will }.
• Let C be a set of courses:
{ 16, 24, 32, 40, 48, 56 }
• Let
R = { ( s, c ) | student s has taken course c }.
• Many students may have taken the same course.
• A student may have taken many courses.
124
Matrix representation of relation R
Relation R: Student s has taken course c
COURSE
S 16 24 32 40 48 56
T
Bill 1 1 0 0 0 0
U
D
Jill 1 1 1 0 0 1
E
N Will 1 0 0 1 0 0
T
128
5.6. Properties of relations
Six properties of relations we will study:
1. Reflexive
2. Irreflexive
3. Symmetric
4. Asymmetric
5. Anti-symmetric
6. Transitive
= < > ≤ ≥
Reflexive
Irreflexive
Symmetric
Asymmetric
Antisymmetric
Transitive
132
Properties of relations summary
= < > ≤ ≥
Reflexive X X X
Irreflexive X X
Symmetric X
Asymmetric X X
Antisymmetric X X X
Transitive X X X X X
133
5.6. Properties of relations
Example: Consider the directed graph of a relation R on the set A = {a, b, c, d, e}.
Which of the properties does R satisfy?
1. reflexive if and only if a R a for every
a A;
2. irreflexive if and only if its
complementary relation is reflexive.
3. symmetric if and only if a R b implies
b R a for every a, b A;
4. asymmetric if and only if (a, b) R
(b, a) R (Asymmetry is the opposite
of symmetry)
5. anti-symmetric if and only if a R b and
b R a implies a = b for every a, b A
(Antisymmetry is not the opposite of
symmetry)
6. transitive if and only if a R b and b R
c implies a R c for every a, b, c A.
134
5.6. Properties of relations
Example: Consider the directed graph of a relation R on the set A = {a, b, c, d, e}.
Which of the properties does R satisfy?
137
Contents
1. Definitions
2. Set operations
3. The algebra of sets
4. Computer representation of sets
5. Relations
6. Functions
138
6. Functions
6.1. Definitions
6.2. Properties of function
6.3. Injective, surjective and bijective function
6.4. Function representation
A B A B A B
-1 -1 3 -1 3
3
0 0 6 0 6
6
4 4 -1 4 -1
-1
7 7 7
f : A→B
142
6. Functions
Example 1: Let A = {a, b}, B = {1, 2, 3}. Which following
relations from A to B are functions from A to B ?
• P = {(a,1), (b,1)}
• Q = {(a,2), (b,3)}
• S = {(a,1)}
• T = {(a,2), (b,1), (b,3)}
0
0
-4 -4
-2
-2
5 5
3
3
8 8
-7
-7
145
Example 2: Are the following relations also functions?
Will all vertical lines cross the graph at only one point?
Will all vertical lines cross the graph at only one point?
NO. x =-2 is used three times.
Example 2: Are the following relations also functions?
x y
-4 0
-2 -3
2 3
-4 1
151
6. Functions
6.1. Definitions
6.2. Properties of function
6.3. Injective, surjective and bijective function
6.4. Function representation
155
6.3. Injective, surjective and bijective function
• A function is called a bijection, if it is injective (1-1) and
surjective (onto).
Examples:
1) Linear functions: f(x)=ax+b when a0
(with domain and co-domain R)
2) Exponential functions: f(x)=bx (b>0, b1)
(with domain R and co-domain R+)
3) Logarithmic functions: f(x)=logbx (b>0, b1)
(with domain R+ and co-domain R)
156
6. Functions
6.1. Definitions
6.2. Properties of function
6.3. Injective, surjective and bijective function
6.4. Function representation
159
6.4. Function representation
• Represent this function by table and matrix
160