Nguyen An Khuong, Huynh Tuong NguyenContents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion 4.1 Chapter 4 Sets and Functions Discrete Struct
Trang 1Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.1
Chapter 4
Sets and Functions
Discrete Structures for Computer Science (CO1007) on Ngày
Trang 2Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Contents
1 Sets
Trang 3Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.3
Set Definition
• Set is afundamentaldiscrete structure on which all discrete
structures are built
• Sets are used to group objects, which often have thesame
properties
Example
• Set of all the students who are currently taking Discrete
Mathematics 1 course
• Set of all the subjects that K2011 students have to take in
the first semester
• Set of natural numbers N
Definition
Asetis an unordered collection of objects
The objects in a set are called theelements(phần tử ) of the set
A set is said tocontain(chứa) its elements
Trang 4Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Notations
Definition
• a ∈ A: a is an element of the set A
• a /∈ A: a isnotan element of the set A
Definition (Set Description)
• The set V of all vowels in English alphabet, V = {a, e, i, o, u}
• Set of all real numbers greater than 1???
{x | x ∈ R, x > 1}
{x | x > 1}
{x : x > 1}
Trang 5Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 6Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Venn Diagram
• John Venn in 1881
• Universal set(tập vũ trụ) is
represented by a rectangle
• Circlesand other
geometrical figuresare used
to represent sets
• Pointsare used to represent
particular elements in set
Trang 7Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.7
Special Sets
• Empty set(tập rỗng ) has no elements, denoted by ∅, or {}
• A set with one element is called asingleton set
• What is {∅}?
• Answer: singleton
Trang 8Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Subset
Definition
The set A is called asubset(tập con) of B iff every element of A
is also an element of B, denoted by A ⊆ B
If A 6= B, we write A ⊂ B and say A is aproper subset(tập con
thực sự) of B
• ∀x(x ∈ A → x ∈ B)
• For every set S,
(i)∅ ⊆ S,(ii)S ⊆ S
Trang 9Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.9
Cardinality
Definition
If S has exactly n distinct elements where n is non-negative
integers, S isfinite set(tập hữu hạn), and n iscardinality(bản
số ) of S, denoted by |S|
Example
• A is the set of odd positive integers less than 10 |A| = 5
• S is the letters in Vietnamese alphabet, |S| = 29
Trang 10Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Power Set
Definition
Given a set S, thepower set(tập lũy thừa) of S is the set of all
subsets of the set S, denoted byP (S)
Example
What is the power set of {0, 1, 2}?
P ({0, 1, 2}) = {∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}
Example
• What is the power set of the empty set?
• What is the power set of the set {∅}
Trang 11Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.11
Power Set
Theorem
If a set has n elements, then its power set has 2n elements
Prove using induction!
Trang 12Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Ordered n-tuples
Definition
Theordered n-tuple(dãy sắp thứ tự) (a1, a2, , an) is the
ordered collection that has a1 as its first element, a2 as its second
element, , and an as its nth element
Trang 13Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.13
Cartesian Product
• René Descartes (1596–1650)
Definition
Let A and B be sets TheCartesian product(tích Đề-các) of A
and B, denoted by A × B, is the set of ordered pairs (a, b), where
Trang 14Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 15Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 16Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 17Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 18Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 19Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 20Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 21Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 22Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Method of Proofs of Set Equations
To prove A = B, we could use
• Venn diagrams
• Prove that A ⊆ B and B ⊆ A
• Usemembership table
• Use set builder notation and logical equivalences
Trang 23Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 24Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 25Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 26Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 27Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.27
Introduction
• Each student is assigned a grade from set
{0, 0.1, 0.2, 0.3, , 9.9, 10.0} at the end of semester
• Function is extremely important in mathematics and
computer science
• linear, polynomial, exponential, logarithmic,
• Don’t worry! For discrete mathematics, we need to
understand functions at a basic set theoretic level
Trang 28Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Function
Definition
Let A and B be nonempty sets A functionf from A to B is an
assignment ofexactly oneelement of B to each element of A
• f : A → B
• For each a ∈ A, if f (a) = b
• b is animage(ảnh) of a
• a ispre-image(nghịch ảnh/tạo ảnh) of f (a)
• f maps (ánh xạ) A to B
f
Trang 29Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 30Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Example
Example
What are domain, codomain, and range of the function that
assigns grades to students includes: student A: 5, B: 3.5, C: 9, D:
5.2, E: 4.9?
Example
Let f : Z → Z assign the the square of an integer to this integer
What is f (x)? Domain, codomain, range of f ?
• f (x) = x2
• Domain: set of all integers
• Codomain: Set of all integers
• Range of f : {0, 1, 4, 9, }
Trang 31Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.31
Add and multiply real-valued functions
Definition
Let f1and f2 be functions from A to R Then f1+ f2 and f1f2
are also functions from A to R defined by
(f1+ f2)(x) = f1(x) + f2(x)(f1f2)(x) = f1(x)f2(x)
Trang 32Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 33Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
• Is f : Z → Z, f(x) = x2
one-to-one?
Trang 34Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
• Is f : Z → Z, f(x) = x2
onto?
Trang 35Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.35
One-to-one and onto (bijection)
Definition
f : A → B isbijective (one-to-one correspondence)(song ánh) if
and only if f isinjectiveandsurjective
• Let f be the function from{a, b, c, d} to {1, 2, 3, 4}
with f (a) = 4, f (b) = 2,
f (c) = 1, f (d) = 3 Is f abijection?
Trang 36Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Example
Trang 37Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
A one-to-one correspondence is callinvertible(khả nghịch)
because we can define the inverse of this function
Trang 38Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 39Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 40Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Function Composition
Definition
Given a pair of functions g : A → B and f : B → C Then the
f ◦ g : A → C
f ◦ g(a) = f (g(a))
Trang 41Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.41Example
Trang 42Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
(0, 0)(1, 1)(2, 4)(3, 9)
Definition
Trang 43Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
(3b) d−xe = −bxc(4a) bx + nc = bxc + n(4b) dx + ne = dxe + n
Trang 44Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 45Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Definition (Fibonacci Sequence)
Initial condition: f0= 0 and f1= 1
Trang 46Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Exercise (1)
Initial deposit: $10,000
Interest: 11%/year,compoundedannually (lãi suất kép)
After 30 years, how much do you have in your account?
Let Pn be the amount in the account after n years The sequence
{Pn} satisfies the recurrence relation
Pn= Pn−1+ 0.11Pn−1= (1.11)Pn−1
The initial condition is P0= 10, 000
Step 1 Solve the recurrence relation (iteration technique)
Trang 47Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
In this sequence, integer 1 appears once, the integer 2 appears
twice, the integer 3 appears three times, and so on Therefore
integer n appears n times in the sequence
We can prove that (try it!)
62
X
i=1
i = 1953
so the next 63 numbers (until 2016) is 63
Therefore, 2012th number in the sequence is 63
Trang 48Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
=Pn+1 k=1ark
=Pn k=0ark+ (arn+1− a)
= Sn+ (arn+1− a)
Trang 49Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.49
Recursion
Definition (Recurrence Relation)
An equation thatrecursively definesa sequence
Definition (Recursion (đệ quy))
The act of defining an object (usually a function) in terms of that
object itself
Trang 50Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Recursive Algorithms
Definition
An algorithm is calledrecursiveif it solves a problem by reducing
it to an instance of the same problem with smaller input
Trang 51Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
else if n = 1 then return 1
else return fibonacci (n-1) + fibonacci (n-2)
Trang 52Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Tower of Hanoi
There is a tower in Hanoi that has three pegs mounted on a board
together with64gold disks of different sizes
Initially, these disks are placed on the first peg in order of size,
with the largest on the borrom
The rules:
1 Move one at a time from one peg to another
2 A disk is never placed on top of a smaller disk
Goals: all the disks on the third peg in order of size
The myth says thatthe world will endwhen they finish the
puzzle
Trang 53Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 54Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Tower of Hanoi – 1 Disc
1
Trang 55Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 56Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Tower of Hanoi – 1 Disc
1
OK
Trang 57Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.57
Tower of Hanoi – 2 Discs
2
1
Trang 58Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Tower of Hanoi – 2 Discs
Moved disc from peg 1 to peg 2
Trang 59Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Trang 60Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
Tower of Hanoi – 2 Discs
21
Moved disc from peg 2 to peg 3
Trang 61Nguyen An Khuong, Huynh Tuong Nguyen
Contents Sets Set Operation Functions One-to-one and Onto Functions Sequences and Summation Recursion
4.61
Tower of Hanoi – 2 Discs
21
OK