Discrete Structures
Discrete Structures
Introduction
Discrete Structures for Computing on January 5, 2022
Course description
Course outline
Document
Some applications
1 Course description
Course outline Course description
Some applications
2 Some applications
0.2
Introduction
Context
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Global
• 12 principal chapters on 45 hours for courses & exercises.
• 10 Homeworks (0%), 1 Assignment (20%) Course description
Course outline
• 2 evaluations: mid-exam (MCQ - 90 minutes - 30%) + final Document
Aims
The content of this subject is mainly a great part of logic, set
theory and graph theory.
This is the mathematical base for many topics of Computational
Science
0.3
Introduction
Subjects in general discrete mathematics course
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
+ Logic
+ Set theory
+ Number theory Course description
Course outline
+ Combinatorics: enumerative combinatorics, graph theory Document
Some applications
+ Algorithmics
+ Information theory
+ Complexity theory
+ Probability theory
+ Proof
+ Counting and Relations
0.4
Introduction
Topics relational to discrete mathematics
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
0.5
Introduction
Context
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Course outline
• Proof methods
• modular arithmetic over integers.
• induction, contradiction.
Course description
• Set theory Course outline
Document
• relations, functions, cardinalities, relation, equivalence equation, partial order
• combinatorics: counting, principles of sum, multiplication, division, inclusion Some applications
and exclusion.
• Graph theory
• directed, undirected, isomorphism
• weighted graphs, algorithm for finding shortest paths
• trees: features, binary trees, minimum spanning trees in connected and
weighted graphs
• flows network
• Probabilistics Modelling
• introductory random variables.
0.6
Introduction
Course learning outcomes
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
L.O.2 Modeling and formulating generic problems in real life by Course description
the discrete mathematical structures and languages Course outline
0.7
Introduction
Document
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
0.8
Introduction
Application
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
• today there is a remarkable variety of applications of mathematics in industry and Some applications
government, such as materials processing, design, medical diagnosis, development
of financial products, network management, weather prediction, etc.
Science Engineering
0.9
Introduction
Computing of algorithm complexity
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Know results
Course description
Size Approximating of computational time
Course outline
n O(log n) O(n) O(n log n) O(n2 ) O(2n ) O(n!) Document
10 3.10−9 s −8
10 s −8
3.10 s −7
10 s 10−6 s 3.10−3 s Some applications
102 7.10−9 s 10−7 s 7.10−7 s 10−5 s 4.1013 y *
103 10−8 s 10−6 s 10−5 s 10−3 s * *
104 1, 3.10−8 s 10−5 s 10−4 s 10−1 s * *
105 1, 7.10−8 s 10−4 s 2.10−3 s 10s * *
106 2.10−8 s 10−3 s 2.10−2 s 17m * *
0.10
Introduction
Mathematical model
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Solver
• Simplex, GLPK
• CPLEX, MPL
Course description
• Excel, Mathlab, etc. Course outline
Document
Some applications
0.11
Introduction
Mathematical model
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
• The carpenter can afford to spend up to 40 hours per week Course outline
Document
0.12
Introduction
Mathematical model
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
0.14
Introduction
Graph
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Course description
Course outline
Document
Some applications
0.16
Introduction
Scheduling
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Course description
Course outline
Document
Some applications
0.17
Introduction
Scheduling
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Exercise
Problem 1||Tmax .
Given 8 jobs with processing times and due dates as follows: Course description
Course outline
Job J1 J2 J3 J4 J5 J6 J7 J8 Document
Some applications
pi 1 2 2 3 3 4 4 3
di 25 16 19 7 18 22 27 8
Let Ci be completion time of job Ji and let Ti = max(0, Ci − di ) its
tardiness.
Question. How to minimize Tmax = maxi Ti ? What is the minimum value of
Tmax ?
0.18
Introduction
Timetabling
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Example
In the bipartite graph below, the vertices P1 , . . . , P6 represent workers and
edges J1 , . . . , J6 of jobs. An edge connects a worker with a job if the worker
has the necessary qualifications to occupy this job. Here, all the edges have an
unit weight 1, mean that Pi has the skill(competence) to operate Jj if there is
an edge between Pi and Jj . Course description
Course outline
Document
P1 P2 P3 P4 P5 P6
Some applications
J1 J2 J3 J4 J5 J6
0.19
Introduction
Game and simulation
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Sally Salon Game Nguyen Tien Thinh
Course description
Course outline
Document
Some applications
0.20
Introduction
Probabilistics Modelling
Huynh Tuong Nguyen,
Nguyen Ngoc Le,
Nguyen Tien Thinh
Calculating of Pi
Course description
Using a Monte-Carlo method to determine an approximate value Course outline
Document
of π : Some applications
randomly draw a great number of points in a square of side 2, and
determine the ratio C/N where N is the total number of points,
and C the number of points whose distance to the center of the
square is ≤ 1).
0.21
Logics
Chapter 1 Ngoc Le
Logics
Discrete Structures for Computing
Contents
Propositional Logic
Logical Equivalences
Exercise
1 Propositional Logic
Contents
Propositional Logic
Logical Equivalences
Exercise
2 Logical Equivalences
3 Exercise
1.2
Logics
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1.3
Logics
Logic
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition (Averroes)
The tool for distinguishing between the true and the false.
Contents
Propositional Logic
Definition (Penguin Encyclopedia) Logical Equivalences
1.4
Logics
Applications in Computer Science
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
• Constructing proofs automatically
• Artificial intelligence
• Many more...
1.5
Logics
Propositional Logic
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A proposition is a declarative sentence that is either true or false,
Contents
but not both.
Propositional Logic
Logical Equivalences
Examples
Exercise
1.6
Logics
Examples
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
• 4>2
• 2n ≥ 100
• The sun circles the earth.
• Today is Thursday.
• Proposition only when the time is specified
1.7
Logics
Notations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Propositional Logic
• Propositions are denoted by p, q, . . .
Logical Equivalences
• The truth value (”chân trị”) is true (T) or false (F) Exercise
1.8
Logics
Operators
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Propositional Logic
Exercise
p ¬p
T F
F T
1.9
Logics
Operators
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Propositional Logic
p q p∧q p q p∨q Logical Equivalences
T T T T T T Exercise
T F F T F T
F T F F T T
F F F F F F
1.10
Logics
Operators
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Propositional Logic
Logical Equivalences
p q p⊕q p q p→q
Exercise
T T F T T T
T F T T F F
F T T F T T
F F F F F T
1.11
Logics
More Expressions for Implication p → q
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• if p, then q
• p implies q
Contents
• p is sufficient for q Propositional Logic
• q if p Logical Equivalences
Exercise
• p only if q
• q unless ¬p
• If you get 100% on the final, you will get 10 grade.
• If you feel asleep this afternoon, then 2 + 3 = 5.
1.12
Logics
Conditional Statements From p → q
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
• q → p (converse - đảo) Propositional Logic
• Prove that only contrapositive have the same truth table with Exercise
p→q
1.13
Logics
Exercise
What are the converse and contrapositive of the following
conditional statement Contents
“If he plays online games too much, his girlfriend leaves him.” Propositional Logic
Logical Equivalences
1.14
Logics
Biconditionals
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
p↔q
“p if and only if q”
Contents
p q p↔q
Propositional Logic
T T T Logical Equivalences
T F F Exercise
F T F
F F T
1.15
Logics
Translating Natural Sentences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
I will buy a new phone only if I have enough money to buy iPhone Contents
Logical Equivalences
• p → (q ∨ ¬r)
1.16
Logics
Translating Natural Sentences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Logical Equivalences
He will not run the red light if he sees the police unless he is too Exercise
risky.
1.17
Logics
Construct Truth Table
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
Construct the truth table of the compound proposition
(p ∨ ¬q) → (p ∧ q). Contents
Propositional Logic
Logical Equivalences
Exercise
p q ¬q p ∨ ¬q p∧q (p ∨ ¬q) → (p ∧ q)
T T F T T T
T F T T F F
F T F F F T
F F T T F F
1.18
Logics
Exercise - Truth table
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
¬p → (¬q ∨ r)
p q r ¬p ¬q ¬q ∨ r ¬p → (¬q ∨ r)
T T T F F T T
T T F F F F F
T F T F T T T
T F F F T T T Contents
F T T T F T T Propositional Logic
F T F T F F F Logical Equivalences
F F T T T T T
Exercise
F F F T T T T
a) (p ∧ q) → ¬q
b) (p ∨ r) → (r ∨ ¬p)
c) (p → q) ∨ (q → p)
d) (p ∨ ¬q) ∧ (¬p ∨ q)
e) (p → ¬q) ∨ (q → ¬p)
f) ¬(¬p ∧ ¬q)
g) (p ∨ q) → (p ⊕ q)
h) (p ∧ q) ∨ (r ⊕ q)
1.19
Logics
Applications
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• “When a user clicked on Help button, a pop-up will be shown Propositional Logic
1.20
Logics
Applications (cont.)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Logic puzzles
• There are two kinds of inhabitants on an island, knights, who Contents
Propositional Logic
always tell the truth, and their opposites, knaves, who may
Logical Equivalences
lie. You encounter two people A and B. What are A and B if
Exercise
A says “B is a knight” and B says ”The two of us are
opposite types”?
• Bit operations
• 101010011 is a bit string of length nine.
1.21
Logics
Tautology and Contradiction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A compound proposition that is always true (false) is called a
tautology - hằng đúng (contradiction - hằng sai). Contents
Logical Equivalences
• Contradiction: mâu thuẫn
Exercise
Example
• p ∨ ¬p (tautology)
• p ∧ ¬p (contradiction)
1.22
Logics
Question
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
b) (p ∧ q) → (p ∨ q) Logical Equivalences
Exercise
c) p → (¬q → p)
d) p → (p → q)
e) p → (p → p)
f) (p → q) → [(p → r) → (q → r)]
1.23
Logics
Proposition? Truth value?
Huynh Tuong Nguyen,
a) “Phan-xi-păng là ngọn núi cao nhất Việt Nam.” Tran Tuan Anh, Nguyen
Ngoc Le
b) “Hai số nguyên tố cùng nhau chỉ có ước chung là 1.”
c) “Tích 3 số nguyên liên tiếp thì chia hết cho 3.”
d) “Hãy đứng lên!”
e) “x+1=0”
f) “Hình lập phương có 8 đỉnh.”
g) “0 là một số dương.”
Contents
h) “Phương trình: x2 + 5x + 6 = 0 vô nghiệm.”
Propositional Logic
i) “2 có phải là số nguyên tố không?”
Logical Equivalences
2
j) “Phương trình mx + 2x − 1 = 0 có nghiệm duy nhất khi và chỉ khi m=-1.”
Exercise
k) “Có số nguyên tố là số chẵn.”
l) “x2 + 1 > 0.”
m) “Bao giờ lớp mình đi dã ngoại?”
n) “Thủy ngân không phải là kim loại.”
o) “320 > 230 .”
p) “Máy bay là phương tiện di chuyển nhanh nhất”
q) “Năm 2002 là năm nhuận.”
r) “Có vô số số nguyên tố.”
s) “210 − 1 chia hết cho 11.”
t) “Cấm hút thuốc lá nơi công cộng.”
u) “Mọi số nguyên dương chẵn lớn hơn 2 là tổng của hai số nguyên tố.”
v) “Số x là nguyên tố nếu nó không có ước số khác 1 và x.”
1.24
Logics
Logical Equivalences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition Contents
The compound compositions p and q are called logically equivalent Propositional Logic
Exercise
Example
Show that ¬(p ∨ q) and ¬p ∧ ¬q are logically equivalent.
1.25
Logics
Logical Equivalences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Logical Equivalences
p∧F ≡ F Luật nuốt
Exercise
1.26
Logics
Logical Equivalences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Logical Equivalences
1.27
Logics
Logical Equivalences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Equivalence hoc
p ∨ ¬p ≡ T Contents
p ∧ ¬p ≡ F Propositional Logic
p→q ≡ ¬p ∨ q Logical Equivalences
(p → q) ∧ (p → r) ≡ p → (q ∧ r) Exercise
(p → r) ∧ (q → r) ≡ (p ∨ q) → r
(p → q) ∨ (p → r) ≡ p → (q ∨ r)
(p → r) ∨ (q → r) ≡ (p ∧ q) → r
p↔q ≡ (p → q) ∧ (q → p)
p↔q ≡ (¬p ∨ q) ∧ (p ∨ ¬q)
4.
1.28
Logics
Constructing New Logical Equivalences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Show that ¬(p ∨ (¬p ∧ q)) and ¬p ∧ ¬q are logically equivalent by
developing a series of logical equivalences.
Solution Contents
Propositional Logic
¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q) by the second De Morgan law Logical Equivalences
Exercise
≡ ¬p ∧ [¬(¬p) ∨ ¬q] by the first De Morgan law
1.29
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Lấy phủ định rồi đơn giản mệnh đề phủ định đó.
Example
p → (¬q ∧ r)
Bằng cách sử dụng bảng chân trị, ta dễ dàng chứng minh được Contents
≡ p ∧ ¬(¬q ∧ r)
≡ p ∧ (q ∨ ¬r)
a) p ∧ (q ∨ r) ∧ (¬p ∨ ¬q ∨ r)
b) (p ∧ q) → r lam lai
c) p ∨ q ∨ (¬p ∧ ¬q ∧ r)
d) [[[(p ∧ q) ∧ r] ∨ [(p ∧ r) ∧ ¬r]] ∨ ¬q] → s
1.30
Logics
Exercise lam lai 1 va 2 Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Propositional Logic
a) ¬(p ↔ q) và ¬p ↔ q Logical Equivalences
b) (p → q) ∧ (p → r) và p → (q ∧ r) Exercise
c) (p → r) ∧ (q → r) và (p ∨ q) → r
d) (p → q) ∨ (p → r) và p → (q ∨ r)
e) ¬p → (q → r) và q → (p ∨ r)
f) p ↔ q và (p → q) ∧ (q → p)
1.32
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Các cặp mệnh đề được cho dưới đây có tương đương logic nhau
không? Chứng minh?
a) p ∧ (p → q) và p ∧ q Contents
Propositional Logic
b) p → q và ¬p ∨ (p ∧ q) Logical Equivalences
c) p → q và ¬p ∨ ¬q Exercise
d) ¬p và ¬(p ∨ q) ∨ (¬p ∧ q)
e) [(p ↔ q) ∧ (q ↔ r) ∧ (r ↔ p)] và
[(p → q) ∧ (q → r) ∧ (r → p)]
f) [(p ∧ q) ∨ (q ∧ r) ∨ (r ∧ p)] và [(p ∨ q) ∧ (q ∨ r) ∧ (r ∨ p)]
1.33
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Xác định chân trị của các mệnh đề sau. Hãy phát biểu mệnh đề
đảo và phản đảo của chúng.
a) “Nếu ABCD là hình chữ nhật thì AB vuông góc CD.”
b) “Nếu 14 là số lẻ thì 15 chia hết cho 4.” Contents
c) “Hai tam giác bằng nhau thì có diện tích bằng nhau.” Propositional Logic
d) “Phương trình bậc hai ax2 + bx + c = 0 có tích a.c < 0 thì nó có nghiệm.” Logical Equivalences
e) “Nếu hai số x và y đều chia hết cho n thì (x + y) cũng chia hết cho n.” Exercise
1.35
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Logical Equivalences
Exercise
A) (p ∧ q) → r
B) p→q
C) p∨q
D) p∧q
E) p↔q
F) ¬p → ¬q
G) ¬p ∨ (p ∧ q)
H) Các chọn lựa khác đều sai.
1.37
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Gọi P , Q, R là các mệnh đề: Ngoc Le
Logical Equivalences
Example Exercise
Bình đang học Toán và Anh Văn nhưng không học Tin học:
P ∧ R ∧ ¬Q
a) Bình đang học Toán và Tin học nhưng không học cùng một
lúc Tin học và Anh Văn.
b) Không đúng là Bình đang học Anh Văn mà không học Toán.
c) Không đúng là Bình đang học Anh Văn hay Tin học mà
không học Toán.
d) Bình không học Tin học lẫn Anh Văn nhưng đang học Toán.
1.38
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Xác định các phát biểu sai trong các phát biểu bên dưới.
a) x ∈ {x}
b) {x} ⊆ {x}
c) {x} ∈ {x} Contents
Propositional Logic
d) {x} ∈ {{x}} Logical Equivalences
e) ∅ ⊆ {x} Exercise
A) a
B) b
C) c
D) d
E) Các đáp án khác đều sai.
1.39
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Propositional Logic
A) (p ∨ ¬q) → q
Logical Equivalences
B) p → (p ∧ q) Exercise
C) ¬p → (p → q)
D) ¬(p → q) → q
E) Các chọn lựa khác đều sai.
1.40
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Cho các mệnh đề sau Ngoc Le
Propositional Logic
Logical Equivalences
Mệnh đề phức hợp nào sau đây biểu diễn định lý: “Nếu tam giác Exercise
ABC là tam giác cân và có một góc bằng 60o thì tam giác đó là
tam giác đều” ?
A) (p ∧ q) → r
B) (p ∧ r) → q
C) (p ∧ r) ∨ q
D) q → (p ∨ r)
E) Các đáp án khác đều sai.
1.41
Logics
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Propositional Logic
b. B và E
Logical Equivalences
c. B và F Exercise
d. A và F
e. A và D
Biết rằng có 4 khẳng định đúng một nửa và một khẳng định sai
hoàn toàn. Hãy cho biết 2 đội nào được thi đấu trong trận chung
kết?
1.42
Exercise Logics
Tìm chân trị các mệnh đề sau (có giải thích ngắn gọn): Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
a) “∀x ∈ N, x2 + 5x + 6 không phải là số nguyên tố.” Ngoc Le
b) “∃x ∈ R, x2 + x + 1 ≤ 0”
c) “∃n ∈ N, (n3 − n) không là bội của 3.”
d) “∀n ∈ N ∗, n2 − 1 là bội của 3.”
e) “∀x, ∀y ∈ R, x2 + y 2 > 2xy”
f) “∃r ∈ Q, 3 < r < π”
g) “∃n ∈ N, n2 + 1 chia hết cho 8” Contents
Exercise
j) “Mọi số thực đều dương.”
k) “Có kim loại ở thể lỏng.”
l) “Mọi tam giác đều đều bằng nhau.”
m) “Tất cả các chất khí đều không dẫn điện.”
n) “Có những tứ giác không có đường tròn ngoại tiếp.”
o) “Tồn tại số tự nhiên n, để với mọi số thực x, ta có f (x) = x2 − 2x + n nhận giá
trị không âm.”
p) “Với mọi số nguyên dương x, với mọi số nguyên dương y ta đều có x ≤ y.”
q) “Với mọi số nguyên dương x, có một số nguyên dương y để x ≤ y.”
r) “Có ít nhất một số nguyên dương x để với mọi số nguyên dương y ta đều có
x ≤ y.”
s) “Tồn tại số nguyên dương x và một số nguyên dương y để có x ≤ y.”
1.44
Logics (cont.)
Chapter 2 Ngoc Le
Logics (cont.)
Discrete Structures for Computing
Contents
Predicate Logic
Exercise
Contents
1 Predicate Logic Predicate Logic
Exercise
2 Exercise
2.2
Logics (cont.)
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
2.3
Logics (cont.)
Limits of Propositional Logic
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Exercise
• All square numbers are not prime numbers. 100 is a square
number. Therefore 100 is not a prime number.
2.4
Logics (cont.)
Predicates
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A predicate (vị từ) is a statement containing one or more Contents
variables. If values are assigned to all the variables in a predicate, Predicate Logic
2.5
Logics (cont.)
Predicates
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
2.6
Logics (cont.)
Truth value
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
• x > 3 is true or false?
Predicate Logic
• 5>3 Exercise
2.7
Logics (cont.)
Quantifiers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
• ∃: Existential – Tồn tại
• ∃xP (x) = There exists an element x such that P (x) is T
• We need a domain of discourse for variable
mien
2.8
Logics (cont.)
Example
Let P (x) be the statement “x < 2”. What is the truth value of the
quantification ∀xP (x), where the domain consists of all real
number?
Contents
• P (3) = 3 < 2 is false Predicate Logic
Example
What is the truth value of the quantification ∃xP (x), where the
domain consists of all real number?
2.9
Logics (cont.)
Example
Express the statement “Some student in this class comes from
Central Vietnam.”
Solution 1 Contents
Predicate Logic
• M (x) = x comes from Central Vietnam
Exercise
• Domain for x is the students in the class
• ∃xM (x)
Solution 2
• Domain for x is all people
• .S(x)
. . : x is the student in the class
ton tai x, S(x) and M(x)
thay Some thanh All => Voi moi x, S(x) -> M(x)
2.10
Logics (cont.)
Negation of Quantifiers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Predicate Logic
Exercise
Example
2.11
Logics (cont.)
Another Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Translate these:
• All lions are fierce.
• Some lions do not drink coffee. Contents
Exercise
Solution
Let P (x), Q(x) and R(x) be the statements “x is a lion”, “x is
fierce” and “x drinks coffee”, respectively.
• ∀x(P (x) → Q(x)).
• ∃x(P (x) ∧ ¬R(x)).
• ∃x(Q(x) ∧ ¬R(x)).
2.12
Logics (cont.)
The Order of Quantifiers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
tru TH cung la voi moi hoac ton tai
• The order of quantifiers is important, unless all the quantifiers
are universal quantifiers or all are existential quantifiers
• Read from left to right, apply from inner to outer
Contents
Example Predicate Logic
∀x ∀y (x + y = y + x) Exercise
T for all x, y ∈ R phai xac dinh bien nao phu thuoc luong tu nao
Example
∀x ∃y (x + y = 0) is T,
while
∃y ∀x (x + y = 0) is F
2.13
Logics (cont.)
Translating Nested Quantifiers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
∀x (C(x) ∨ ∃y (C(y) ∧ F (x, y)) )
Provided that: Contents
Exercise
• F (x, y): x and y are friends,
• x, y ∈ all students in your school.
Answer
For every student x in your school, x has a computer or there is a
student y such that y has a computer and x and y are friends.
2.14
Logics (cont.)
Translating Nested Quantifiers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
∃x∀y∀z (((F (x, y) ∧ F (x, z) ∧ (y 6= z)) → ¬F (y, z)))
Provided that: Contents
Predicate Logic
• F (x, y): x, y are friends
Exercise
• x, y, z ∈ all students in your school.
Answer
There is a student x, so that for every student y, every student z
not the same as y, if x and y are friends, and x and z are friends,
then y and z are not friends.
2.15
Logics (cont.)
Translating into Logical Expressions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Predicate Logic
Exercise
Answer
Assume:
C(x) : x has visited Hanoi
D(x) : x has visited Nha Trang
E(x) : x has visited Vung Tau
We have:
1 ∃xC(x)
2 ∀x(D(x) ∨ E(x))
2.16
Logics (cont.)
Translating into Logical Expressions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Every people has only one best friend. Contents
Predicate Logic
Exercise
Solution
Assume:
• B(x, y) : y is the best friend of x
We have:
∀x∃y∀z(B(x, y) ∧ ((y 6= z) → ¬B(x, z)))
2.17
Logics (cont.)
Translating into Logical Expressions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
If a person is a woman and a parent, then this person is mother of
some one. Contents
Predicate Logic
Solution Exercise
We define:
• W (x) : x is woman
• P (x) : x is a parent
• M (x, y): x is mother of y
We have:
∀x((W (x) ∧ P (x)) → ∃yM (x, y))
2.18
Logics (cont.)
Inference
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Predicate Logic
special day, I will surely buy her some expensive gift.
Exercise
• If I buy my girlfriend expensive gifts, I will eat noodles for a
week.
• Today is March 8.
• March 8 is such a special day.
• Therefore, if I have a girlfriend,...
• I will eat noodles for a week.
chi xet cac TH gia thuyet deu dung, neu co 1 TH ra ket luan sai thi do la
suy dien sai, dung het thi dung
2.19
Logics (cont.)
Propositional Rules of Inferences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Predicate Logic
¬q Exercise
p→q
∴ ¬p Modus tollens
p→q
q→r
Hypothetical syllogism
∴p→r
(Tam đoạn luận giả định)
p∨q
¬p
Disjunctive syllogism
∴q
(Tam đoạn luận tuyển)
2.20
Logics (cont.)
Propositional Rules of Inferences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Predicate Logic
p∧q
Simplification Exercise
∴p
(Rút gọn)
p
q
Conjunction
∴p∧q
(Kết hợp)
p∨q
¬p ∨ r
Resolution
∴q∨r
(Phân giải)
2.21
Logics (cont.)
Predicate Logic
Solution Exercise
• p: It is raining today
• q: We will not have a barbecue today
• r: We will have barbecue tomorrow
p→q
q→r
∴p→r
Hypothetical syllogism
2.22
Logics (cont.)
Example
1. ¬p ∧ q Hypothesis
• It is not sunny this afternoon
(¬p) and it is colder than 2. ¬p Simplification using (1)
yesterday (q)
Contents
• We will go swimming (r) only if 3. r → p Hypothesis Predicate Logic
it is sunny Exercise
4. ¬r Modus tollens using (2) and (3)
• If we do not go swimming, then
we will take a canoe trip (s) 5. ¬r → s Hypothesis
• If we take a canoe trip, then we
will be home by sunset (t) 6. s Modus ponens using (4) and (5)
• We will be home by sunset (t)
7. s → t Hypothesis
2.23
Logics (cont.)
Fallacies
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Fallacies (ngụy biện) resemble rules of inference but are based on
contingencies rather than tautologies. Contents
Predicate Logic
Exercise
Example
If you do correctly every questions in mid-term exam, you will get
10 grade. You got 10 grade.
Therefore, you did correctly every questions in mid-term exam.
Is [(p → q) ∧ q] → p a tautology?
2.24
Logics (cont.)
Rules of Inference for Quantified Statements
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
P (c)for an arbitrary c
Universal generalization
∴ ∀xP (x)
(Tổng quát hóa phổ quát)
∃xP (x)
Existential instantiation
∴ P (c)for some element c
(Cụ thể hóa tồn tại)
P (c)for some element c
Existential generalization
∴ ∃xP (x)
(Tổng quát hóa tồn tại)
2.25
Logics (cont.)
Example
Exercise
Hint
• C(x): x is in this class
• B(x): x has gone to class
• P (x): x passed the first exam
• Premises???
2.26
Logics (cont.)
2.27
Logics (cont.)
Xét vị từ p(x) :00 x2 − 3x + 2 = 000 . Cho biết chân trị các mệnh đề
sau:
a) p(0)
b) p(1)
c) p(2) Contents
Predicate Logic
d) ∃x, p(x) Exercise
e) ∀x, p(x)
a) F
b) T
c) T
d) T
e) F
2.28
Xét vị từ theo 2 biến nguyên dương: p(x, y): “x là ước của y” Logics (cont.)
Hãy xác định chân trị các mệnh đề sau: Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
a) p(2, 3) Ngoc Le
b) p(2, 6)
c) ∀y, p(1, y)
d) ∀x, p(x, x)
Exercise
g) ∀x∀y, (p(x, y) ∧ p(y, x)) → (x = y)
a) F
b) T
c) T
d) T
e) T
f) F
g) T
h) T 2.29
Logics (cont.)
Predicate Logic
Xác định các biểu thức luận lý vị từ để diễn đạt các câu sau Exercise
2.30
Logics (cont.)
Lời giải - Xác định các biểu thức luận lý vị từ để diễn đạt các câu
sau
a) ∃x∃y(S(x, m) ∧ O(x, m) ∧ B(y, m) ∧ ¬O(y, m)).
Contents
b) ∀x(B(x, m) → ¬O(x, m)).
Predicate Logic
c) ∃x∀y H(x, Thuyen) ∧ H(y, Thuyen) → (x = y) Exercise
2.31
Logics (cont.)
Exercise
2.32
Logics (cont.)
bộ sinh viên trong lớp Toán. Hãy phát biểu các vị từ sau:
a) ∃xN (x)
b) ∀xN (x)
c) ¬∃xN (x)
Contents
d) ∃x¬N (x) Predicate Logic
f) ∀x¬N (x)
2.33
Logics (cont.)
Cho vị từ N (x) “x học ở lớp hơn 5 giờ mỗi ngày trong tuần” với
tập vũ trụ là toàn bộ sinh viên trong lớp Toán. Hãy phát biểu các
vị từ sau:
a) ∃xN (x)
Contents
b) ∀xN (x) Predicate Logic
d) ∀x¬N (x)
a) Có một sinh viên học ở lớp hơn 5 giờ mỗi ngày trong tuần.
b) Mọi sinh viên đều học ở lớp hơn 5 giờ mỗi ngày trong tuần.
c) Có một sinh viên không học ở lớp hơn 5 giờ mỗi ngày trong tuần.
d) Không có sinh viên nào học ở lớp hơn 5 giờ mỗi ngày trong tuần.
2.34
Logics (cont.)
Hãy cho biết công thức vị từ của đoạn mã giả (pseudo code) sau:
return false;
}
return true;
2.35
Logics (cont.)
Hãy cho biết công thức vị từ của đoạn mã giả (pseudo code) sau:
Exercise
return true;
}
return false;
2.36
Logics (cont.)
Predicate Logic
//— Now look for a second match Exercise
for (y=0; (y<numKids)&&(y!=x); y++)
if isParent(Peter, kids[y])
match2Found = true;
2.37
Logics (cont.)
2.38
Cho L(x,y) là câu "x yêu y", với không gian của cả x và y là tập Logics (cont.)
hợp mọi người trên thế giới. Hãy dùng các lượng từ để diễn đạt Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
các câu sau Ngoc Le
a) Mọi người đều yêu Jerry.
b) Mọi người đều yêu một ai đó.
c) Có một người mà tất cả mọi người đều yêu.
d) Không có ai yêu tất cả mọi người.
e) Có một người mà Lydia không yêu.
f) Có một người mà không ai yêu.
g) Có đúng một người mà tất cả mọi người đều yêu. Contents
Diễn giải những công thức vị từ sau dưới dạng ngôn ngữ tự nhiên Exercise
2.40
Logics (cont.)
2.41
Logics (cont.)
Chuyển các câu sau sang vị từ, lượng từ và toán tử logic: Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
a) Không có ai là hoàn hảo. Ngoc Le
Exercise
C(x): x là hoàn hảo.
D(x): x là bạn của bạn.
E(x): x là bất kỳ người nào khác.
a) ¬∃xC(x)
b) ∃x¬C(x)
c) ∀xD(x) → C(x)
d) ∃x∀y(D(x) ∧ D(y) ∧ (x 6= y)) → C(x) =⇒ ∃y(D(y) → C(y))
e) ∀x(D(x) ∧ C(x))
f) ∀x∃y(D(y) ∧ (y 6= x) ∨ ¬C(y)) =⇒ ¬∀xD(x) ∨ ∃yC(y)
2.42
Logics (cont.)
Predicate Logic
Mệnh đề vị từ nào sau biểu diễn câu : "Mọi chương trình đào tạo
Exercise
nếu có mục tiêu giống một chương trình khác đã đáp ứng chuẩn
ABET và kết quả đầu ra có thể kiểm chứng được thì cũng tuân
theo chuẩn ABET"
A) ∀x(P (x) ∧ ¬Q(x)) → ∃x(R(x))
B) ∀x(∃y(Q(x, y) ∧ P (y) ∧ R(x)) → P (x))
C) ∀x(∃y(Q(x, y) ∧ P (y) ∧ R(x)) → P (x) ∨ R(x))
D) ∀x(∀y(Q(x, y) ∧ P (y) ∨ R(x)) → P (x))
2.43
Logics (cont.)
A) v là anh của w
B) v là cháu trai của w
C) v là chú của w
D) v là ông của w
2.44
Logics (cont.)
a) Khi ổ cứng còn ít hơn 30 GB, một thông điệp cảnh báo sẽ
được gửi tới mọi người dùng.
b) Không được sao lưu hệ thống tập tin nếu có một người nào
đó đang đăng nhập vào hệ thống.
c) Đoạn phim Youtube sẽ được buffer khi còn ít nhất 8 MB bộ Contents
Exercise
d) Chỉ vài sinh viên máy tính lập trình tốt.
e) Không một sinh viên máy tính nào không cần cù.
f) Không phải tất cả các sinh viên máy tính đều thông minh.
g) Tất cả người Pompei hoặc trung thành với Caesar hoặc ghét
ông ta.
h) Mỗi người đều trung thành với một người nào đó.
i) Người ta chỉ muốn ám sát những nhà cầm quyền mà người ta
không trung thành.
2.45
Proving methods
Chapter 3 Ngoc Le
Proving methods
Discrete Structures for Computing
Contents
Proving Methods
Exercise
Contents
1 Proving Methods Proving Methods
Exercise
2 Exercise
3.2
Proving methods
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
3.3
Proving methods
Introduction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Definition
Proving Methods
A proof is a sequence of logical deductions from Exercise
- axioms, and
- previously proved theorems
that concludes with a new theorem.
3.4
Proving methods
Terminology
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Proving Methods
Exercise
3.5
Proving methods
Contents
Proving Methods
Exercise
• Lemma (bổ đề ) = less important theorem that is helpful in
the proofs of other results
• Corollary (hệ quả ) = a theorem that can be established
directly from a proved theorem
• Conjecture (phỏng đoán) = statement being proposed to be
true, when it is proved, it becomes theorem
3.6
Proving methods
Proving a Theorem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Proving Methods
Goal:
Exercise
• Show that P (c) → Q(c) is true with arbitrary c of the domain
• Apply universal generalization
⇒ How to show that conditional statement p → q is true.
3.7
Proving methods
Methods of Proof
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
• Direct proofs (chứng minh trực tiếp)
Proving Methods
• Proof by contraposition (chứng minh phản đảo) Exercise
3.8
Proving methods
Direct Proofs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A direct proof shows that p → q is true by showing that if p is
Contents
true, then q must also be true. Proving Methods
Exercise
Example
3.9
Proving methods
Proof by Contraposition
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
p → q can be proved by showing (directly) that its contrapositive,
¬q → ¬p, is true. Contents
Proving Methods
Exercise
Example
3.10
Proving methods
Proofs by Contradiction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
p is true if if can show that ¬p → (r ∧ ¬r) is true for some
proposition r.
Contents
√ Exercise
Ex.: Prove that 2 is irrational.
√
Pr.: Let p is the proposition
√ “ 2 is irrational”. Suppose
√ ¬p is true,
which means 2 is rational. If so, ∃a, b ∈ Z, 2 = a/b, a, b
have no common factors. Squared, 2 = a2 /b2 , 2b2 = a2 , so
a2 is even, and a is even, too. Because of that a = 2c, c ∈ Z.
Thus, 2b2 = 4c2 , or b2 = 2c2 , which means b2 is even and so
is b. That means 2 divides both a and b, contradict with the
assumption.
3.11
Proving methods
Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Proving Methods
Exercise
3.12
Proving methods
Mathematical Induction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition (Induction)
To prove that P (n) is true for all positive integers n, where P (n)
Contents
is a propositional function, we complete two steps:
Proving Methods
• Basis Step: Verify that P (1) is true. Exercise
3.13
Proving methods
Example on Induction
Huynh Tuong Nguyen,
Example Tran Tuan Anh, Nguyen
Ngoc Le
n(n + 1)
1 + 2 + ... + n = .
2
Contents
Let P (n) be the proposition that sum of first n is n(n + 1)/2 Exercise
Example
Prove that n < 2n for all positive integers n.
Solution Contents
Exercise
• Basis Step: P (1) is true, because 1 < 21 = 2
• Inductive Step:
Assume that P (k) is true for the positive k, that is, k < 2k .
Add 1 to both side of k < 2k , note that 1 ≤ 2k .
k + 1 < 2k + 1 ≤ 2k + 2k = 2 · 2k = 2k+1 .
3.15
Proving methods
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
1 Chứng minh trực tiếp.
2 Chứng minh gián tiếp (phản đảo).
3 Chứng minh phản chứng.
3.16
Proving methods
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Proving Methods
Để chứng minh phát biểu trên là đúng. Ta viết phát biểu này dưới dạng phép kéo theo
p → q với p = 7n + 9 là số chẵn và q = n là số lẻ. Exercise
Đảo đề của nó là "Nếu n không là số lẻ thì 7n + 9 không là số chẵn". Và ta có thể
chứng minh phát biểu này đúng như sau:
Nếu n không là số lẽ, nghĩa là n chia hết cho 2. Do đó, n = 2k, (k ∈ Z)
Ta suy ra: 7n + 9 = 7(2k) + 9 = 14k + 9 = 2(7k + 4) + 1
Nghĩa là: 7n + 9 không là số chẵn. Vì mệnh đề phản đảo là đúng nên do chứng minh đảo
đề, ta suy ra p → q cũng đúng.
3.17
Proving methods
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Kiểu chứng minh nào đã được sử dụng trong chứng minh bên dưới
đây
Để chứng minh “Nếu m và n là những số nguyên và mn là chẵn, thì
Contents
hoặc là m chẵn, hoặc là n chẵn”, người ta suy diễn như sau:
Proving Methods
Giả sử m và n là số lẻ. Khi đó có thể biểu diễn m = 2k + 1 và
Exercise
n = 2l + 1. Như vậy tích mn = (2k + 1)(2l + 1) = 2(2kl + k + l) + 1 là
số lẻ. Sai giả thiết. Kết luận, hoặc là m chẵn, hoặc là n chẵn.
3.18
Proving methods
hoa trong một tập n bông hoa bất kỳ đều có cùng màu sắc. Proving Methods
Exercise
(4) Xét một tập bất kỳ n + 1 bông; được đánh số lần lượt là
1, 2, 3, . . . , n, (n + 1).
(5) Dựa theo giả định trên, chuỗi n bông hoa đầu tiên của những
bông hoa này có cùng màu, và chuỗi n bông hoa sau cũng sẽ
có cùng một màu.
(6) Do hai tập hợp bông hoa này có sự giao thoa n − 1 bông,
nên tất cả n + 1 bông hoa này phải cùng một màu.
(7) Điều này chứng minh rằng P (n + 1) là đúng và được chứng
minh bằng phương pháp qui nạp.
3.19
Proving methods
Xét một tập con D (N × N ) được đinh nghĩa đệ quy như sau:
(i) (n, 0) ∈ D.
(ii) nếu (n, m) ∈ D, thì (n, n + m) ∈ D. Contents
Exercise
1) xác định vài phần tử của D.
2) chứng minh bằng phép quy nạp trên k rằng ’nếu m = k.n thì
’(n, m) ∈ D’.
3) chứng minh rằng nếu (n, m) ∈ D, thì chúng ta sẽ có m = kn
với k ∈ N .
3.20
Proving methods
dương để có thể viết m dưới dạng tổng bình phương của 12 , Exercise
22 , . . ., n2 , nghĩa là: ∀m ∈ N + , ∃n ∈ N + ,
∃ε1 , . . . , εn ∈ {−1, 1}, m = ε1 12 + ε2 22 + . . . + εn n2 .
(Gợi ý: thử biểu diễn các giá trị m ∈ {1, 2, 3, 4, 5, 6})
3.21
Proving methods
Hãy chứng minh các đẳng thức sau bằng cách sử dụng phương
pháp chứng minh quy nạp:
Contents
1 1.2 + 2.5 + 3.8 + . . . + n.(3n − 1) = n2 (n + 1), n ≥ 1 Proving Methods
1 1 1 2n
2 1 + 1+2 + 1+2+3 + ... + 1+2+3+...+n = n+1 , n ≥1 Exercise
Pn i−1 n
3 i=1 2 =2 −1
4 Chứng minh log5 (2) là số vô tỷ.
3.22
Proving methods
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Hãy sử dụng phương pháp chứng minh quy nạp để chứng minh:
1 Chứng minh rằng với mọi số nguyên n ≥ 1, 32n−1 + 1 chia
hết cho 4. Contents
2 Chứng minh rằng với mọi số nguyên n ≥ 1, 6n − 1 đều chia Proving Methods
2n−1
3 Chứng minh rằng với mọi số nguyên n ≥ 1, 5 + 1 đều
chia hết cho 6.
4 Chứng minh rằng với mọi số nguyên n ≥ 1, 8n − 1 đều chia
hết cho 7.
5 Chứng minh rằng với mọi số nguyên n ≥ 1, 4n + 15n − 1 đều
chia hết cho 9.
3.24
Proving methods
Hãy chứng minh các bất đẳng thức sau bằng cách sử dụng
Contents
phương pháp chứng minh quy nạp: Proving Methods
n
2 Chứng minh rằng với mọi số nguyên n ≥ 4, n! > 2 .
3.26
Proving methods
Contents
Chứng minh rằng số lượng đường chéo trong một đa giác lồi với n Proving Methods
đỉnh là 12 n(n − 3), với n ≥ 4 Exercise
3.36
Sets
Chapter 4
Ngoc Le
Sets
Discrete Structures for Computing
Contents
Sets
Set Operation
Contents
1 Sets Sets
Set Operation
2 Set Operation
4.2
Sets
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
4.3
Sets
Set Definition
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Set is a fundamental discrete structure on which all discrete
structures are built
• Sets are used to group objects, which often have the same
properties
Contents
Example
Sets
• Set of all the students who are currently taking Discrete Set Operation
Mathematics 1 course.
• Set of all the subjects that K2011 students have to take in
the first semester.
• Set of natural numbers N
Definition
A set is an unordered collection of objects.
The objects in a set are called the elements (phần tử ) of the set.
A set is said to contain (chứa) its elements.
4.4
Sets
Notations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• a ∈ A: a is an element of the set A
• a∈/ A: a is not an element of the set A Contents
Sets
Set Operation
Definition (Set Description)
4.5
Sets
Equal Sets
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Two sets are equal iff they have the same elements. Contents
Sets
Example
• {1, 3, 5} = {3, 5, 1}
• {1, 3, 5} = {1, 3, 3, 3, 5, 5, 5, 5}
4.6
Sets
Venn Diagram
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Sets
represented by a rectangle
Set Operation
• Circles and other
geometrical figures are used
to represent sets
• Points are used to represent
particular elements in set
Tap vu tru = U
4.7
Sets
Special Sets
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
• Empty set (tập rỗng ) has no elements, denoted by ∅, or {}
Sets
• A set with one element is called a singleton set Set Operation
• What is {∅}?
• Answer: singleton
4.8
Sets
Subset
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The set A is called a subset (tập con) of B iff every element of A
is also an element of B, denoted by A ⊆ B.
Contents
• ∀x(x ∈ A → x ∈ B)
• For every set S,
(i) ∅ ⊆ S, (ii) S ⊆ S.
4.9
Sets
Cardinality
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
If S has exactly n distinct elements where n is non-negative
integers, S is finite set (tập hữu hạn), and n is cardinality (bản
số ) of S, denoted by |S|.
Contents
Example Sets
• A is the set of odd positive integers less than 10. |A| = 5. Set Operation
Definition
A set that is infinite if it is not finite.
Example
4.10
Sets
Power Set
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Given a set S, the power set (tập lũy thừa) of S is the set of all
subsets of the set S, denoted by P (S).
Contents
Sets
Example
Set Operation
Example
4.11
Sets
Power Set
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Theorem Sets
If a set has n elements, then its power set has 2n elements. Set Operation
4.12
Sets
Ordered n-tuples
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The ordered 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
Contents
element, . . ., and an as its nth element. Sets
Set Operation
Definition
Two ordered n-tuples (a1 , a2 , . . . , an ) = (b1 , b2 , . . . , bn ) iff ai = bi ,
for i = 1, 2, . . . , n.
Example
2-tuples, or ordered pairs (cặp), (a, b) and (c, d) are equal iff
a = c and b = d
4.13
Sets
Cartesian Product
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Let A and B be sets. The Cartesian product (tích Đề-các) of A
and B, denoted by A × B, is the set of ordered pairs (a, b), where Contents
Set Operation
A × B = {(a, b) | a ∈ A ∧ b ∈ B}
U x {} = {}
Example
Cartesian product of A = {1, 2} and B = {a, b, c}. Then
A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}
Show that A × B 6= B × A
4.14
Sets
Cartesian Product
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Sets
Set Operation
Example
A = {0, 1}, B = {1, 2}, C = {0, 1, 2}. What is A × B × C?
A×B×C = {(0, 1, 0), (0, 1, 1), (0, 1, 2), (0, 2, 0), (0, 2, 1),
(0, 2, 2), (1, 1, 0), (1, 1, 1), (1, 1, 2), (1, 2, 0),
(1, 2, 1), (1, 2, 2)}
4.15
Sets
Union
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The union (hợp) of A and B
A ∪ B = {x | x ∈ A ∨ x ∈ B}
Contents
Sets
A B
• Example:
• {1,2,3} ∪ {2,4} = {1,2,3,4}
• {1,2,3} ∪ ∅ = {1,2,3}
4.16
Sets
Intersection
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The intersection (giao) of A and B
A ∩ B = {x | x ∈ A ∧ x ∈ B}
Contents
Sets
A B
Example:
• {1,2,3} ∩ {2,4} = {2}
• {1,2,3} ∩ N = {1,2,3}
4.17
Sets
Union/Intersection
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
n
Sets
[
Ai = A1 ∪ A2 ∪ ... ∪ An = {x | x ∈ A1 ∨ x ∈ A2 ∨ ... ∨ x ∈ An } Set Operation
i=1
n
\
Ai = A1 ∩ A2 ∩ ... ∩ An = {x | x ∈ A1 ∧ x ∈ A2 ∧ ... ∧ x ∈ An }
i=1
4.18
Sets
Difference
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The difference (hiệu) of A and B
A − B = {x | x ∈ A ∧ x ∈
/ B}
Contents
Sets
A B
Example:
• {1,2,3} - {2,4} = {1,3}
• {1,2,3} - N = ∅
4.19
Sets
Complement
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The complement (phần bù) of A
A = {x | x ∈A}
/
Contents
Sets
Set Operation
Example:
• A = {1,2,3} then A = ???
• Note that A - B = A ∩ B
4.20
Sets
Set Identities
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
4.21
Sets
Set Identities
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) Distributive laws
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) Luật phân phối
A∪B = A∩B De Morgan’s laws
A∩B = A∪B Luật De Morgan
4.22
Sets
Method of Proofs of Set Equations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Set Operation
• Prove that A ⊆ B and B ⊆ A
• Use membership table
• Use set builder notation and logical equivalences
4.23
Sets
Example (1)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Sets
Set Operation
Example
Verify the distributive rule P ∪ (Q ∩ R) = (P ∪ Q) ∩ (P ∪ R)
4.24
Sets
Example (2)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Prove: A ∩ B = A ∪ B
Contents
(1) Show that A ∩ B ⊆ A ∪ B Sets
4.25
Sets
Example (3)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Prove: A ∩ B = A ∪ B
Contents
Set Operation
1 1 1 0 0
1 0 0 1 1
0 1 0 1 1
0 0 0 1 1
4.26
Sets
Example (4)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Prove: A ∩ B = A ∪ B
A∩B = {x|x 6∈ A ∩ B} Contents
4.27
Functions
Chapter 5 Ngoc Le
Functions
Discrete Structures for Computing
Contents
Functions
Sequences and
Summation
Recursion
1 Functions
Contents
Functions
2 One-to-one and Onto Functions One-to-one and Onto
Functions
Sequences and
Summation
4 Recursion
5.2
Functions
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
5.3
Functions
Introduction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Sequences and
• linear, polynomial, exponential, logarithmic,... Summation
5.4
Functions
Function
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition Ngoc Le
f
a b = f (a)
A B
f
5.5
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example:
• y is an image of d
• c is a pre-image of z Contents
Functions
Sequences and
Summation
Recursion
5.6
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
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? Contents
Functions
Let f : Z → Z assign the the square of an integer to this integer. Sequences and
Summation
What is f (x)? Domain, codomain, range of f ? Recursion
• f (x) = x2
• Domain: set of all integers
• Codomain: Set of all integers
• Range of f : {0, 1, 4, 9, . . .}
5.7
Functions
Add and multiply real-valued functions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Let f1 and f2 be functions from A to R. Then f1 + f2 and f1 f2
are also functions from A to R defined by
(f1 + f2 )(x) = f1 (x) + f2 (x) Contents
Functions
(f1 f2 )(x) = f1 (x)f2 (x) One-to-one and Onto
Functions
Sequences and
Summation
Example Recursion
5.8
Functions
Image of a subset
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Let f : A → B and S ⊆ A. The image of S:
Functions
Recursion
5.9
Functions
One-to-one
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A function f is one-to-one or injective (đơn ánh) if and only if
Contents
∀a∀b (f (a) = f (b) → a = b) Functions
Sequences and
Summation
• Is f : Z → Z, f (x) = x + 1 Recursion
one-to-one?
• Is f : Z → Z, f (x) = x2
one-to-one?
5.10
Functions
Onto
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
f : A → B is onto or surjective (toàn ánh) if and only if
Contents
∀b ∈ B, ∃a ∈ A : f (a) = b Functions
Sequences and
Summation
• Is f : Z → Z, f (x) = x + 1 Recursion
onto?
• Is f : Z → Z, f (x) = x2
onto?
5.11
Functions
One-to-one and onto (bijection)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
f : A → B is bijective (one-to-one correspondence) (song ánh) if
Contents
and only if f is injective and surjective
Functions
5.12
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
Recursion
5.13
Functions
Inverse function (Hàm ngược)
Huynh Tuong Nguyen,
Definition Tran Tuan Anh, Nguyen
Ngoc Le
Sequences and
f (a) Summation
Recursion
A f B
f −1
5.14
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
A = {a, b, c} and B = {1, 2, 3} with
Contents
f (a) = 2 f (b) = 3 f (c) = 1 Functions
Sequences and
Summation
−1 −1 −1
f (1) = c f (2) = a f (3) = b Recursion
Example
Let f : R → R with f (x) = x2 . If f invertible?
5.15
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
f :R→R
Contents
Functions
f (x) = 2x + 1 One-to-one and Onto
Functions
Sequences and
f −1 : R → R Summation
Recursion
x−1
f −1 (x) =
2
5.16
Functions
Function Composition
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Given a pair of functions g : A → B and f : B → C. Then the Contents
Functions
composition (hợp thành) of f and g, denoted f ◦ g is defined by
One-to-one and Onto
Functions
f ◦g :A→C Sequences and
Summation
Recursion
f ◦ g(a) = f (g(a))
5.17
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
Recursion
5.18
Functions
Graphs of Functions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
The graph of f (x) = x2 from Z to Z.
(−3, 9) (3, 9)
Contents
Functions
Sequences and
Summation
(0, 0)
Definition
Let f be a function from the set A to the set B. The graph of the
function f is the set of ordered pairs {(a, b) | a ∈ A and f (a) = b}.
5.19
Functions
Important Functions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition Ngoc Le
Functions
Bảng: Properties (n is an integer, x is a real number) One-to-one and Onto
Functions
Sequences and
(1a) bxc = n iff n≤x<n+1 Summation
Functions
1, 12 , 14 , 81 , 16
1 1 Summation
,... an = 2n−1
Recursion
Geometric sequence (cấp số nhân)
Example
{an } 5, 11, 17, 23, 29, 35, 41, 47, . . . an = 6n − 1
{bn } 1, 7, 25, 79, 241, 727, 2185, . . . bn = 3n − 2
5.21
Functions
Recurrence Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
{an } 5, 11, 17, 23, 29, 35, 41, 47, . . .
an = an−1 + 6 for n = 2, 3, 4, . . . and a1 = 5
Recurrence relations: công thức truy hồi
Contents
Functions
Definition (Fibonacci Sequence)
One-to-one and Onto
Functions
Initial condition: f0 = 0 and f1 = 1
Sequences and
fn = fn−1 + fn−2 for n = 2, 3, 4, . . . Summation
Recursion
Example
Find the Fibonacci numbers f2 , f3 , f4 , f5 and f6
f2 = f1 + f0 =1+0=1
f3 = f2 + f1 =1+1=2
f4 = f3 + f2 =2+1=3
f5 = f4 + f3 =3+2=5
f6 = f5 + f4 =5+3=8
5.22
Functions
Functions
integer n appears n times in the sequence.
One-to-one and Onto
Functions
We can prove that (try it!)
n Sequences and
X n(n + 1) Summation
i = 1 + 2 + 3 + ... + n = Recursion
i=1
2
and can easily calculate that
X62
i = 1953
i=1
so the next 63 numbers (until 2016) is 63.
Therefore, 2012th number in the sequence is 63.
5.24
Functions
n ar n+1 −a
X if r 6= 1
arj = r−1
j=0
(n + 1)a if r = 1.
Contents
Sequences and
Pn Summation
rSn = r j=0 arj Recursion
Pn
= j=0 arj+1
Pn+1
= k=1 ark
Pn k
= k=0 ar + (arn+1 − a)
= Sn + (arn+1 − a)
ar n+1 −a
Solving for Sn shows that if r 6= 1, then Sn = r−1
Pn
If r = 1, then Sn = j=0 a = (n + 1)a
5.25
Functions
Recursion
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition (Recurrence Relation) Ngoc Le
Sequences and
Summation
Recursion
5.26
Functions
Recursive Algorithms
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
An algorithm is called recursive if it solves a problem by reducing
it to an instance of the same problem with smaller input.
Contents
Example Functions
Recursion
Solution. We base on the recursive definition of n!:
n! = n · (n − 1)! and 0! = 1.
procedure factorial (n: nonnegative integer)
if n = 0 then return 1
else return n· factorial (n - 1)
{output is n!}
5.27
Functions
Algorithms for Fibonacci Numbers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Recursive Algorithm Ngoc Le
Functions
The myth says that the world will end when they finish the
puzzle.
5.29
Functions
Tower of Hanoi – 64 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1
2
3
4
? Contents
Functions
Sequences and
Summation
5 Recursion
5.30
Functions
Tower of Hanoi – 1 Disc
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
Recursion
5.31
Functions
Tower of Hanoi – 1 Disc
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
Recursion
5.32
Functions
Tower of Hanoi – 1 Disc
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
OK Contents
Functions
Sequences and
Summation
Recursion
5.33
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 Recursion
5.34
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
Recursion
2 1
5.35
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
Recursion
1 2
5.36
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 Recursion
5.37
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
OK Contents
Functions
Sequences and
Summation
1 Recursion
5.38
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
5.39
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
2 Recursion
3 1
5.40
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
Recursion
3 2 1
5.41
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 Recursion
3 2
5.42
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 Recursion
2 3
5.43
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
Recursion
1 2 3
5.44
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
2 Recursion
1 3
5.45
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
5.46
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
OK 1
Contents
Functions
Sequences and
Summation
2 Recursion
5.47
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
5.48
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
4 1
5.49
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
3 Recursion
4 1 2
5.50
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
3 1 Recursion
4 2
5.51
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 Recursion
4 3 2
5.52
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 Recursion
4 3 2
5.53
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 2 Recursion
4 3
5.54
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
4 3
5.55
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
3 4
5.56
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
2 1 Recursion
3 4
5.57
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 Recursion
2 3 4
5.58
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 Recursion
2 3 4
5.59
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
1 3 Recursion
2 4
5.60
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
Sequences and
Summation
3 Recursion
2 1 4
5.61
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
1 4
5.62
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Functions
5.63
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
OK 1
2
Contents
Functions
Sequences and
Summation
3 Recursion
5.64
Functions
Tower of Hanoi
Huynh Tuong Nguyen,
Algorithm Tran Tuan Anh, Nguyen
Ngoc Le
procedure hanoi(n, A, B, C)
if n = 1 then move the disk from A to C
else
call hanoi(n − 1, A, C, B)
move disk n from A to C Contents
call hanoi(n − 1, B, A, C) Functions
Recurrence Solving
H(n) = 2n − 1
If one move takes 1 second, for n = 64
Chapter 6 Ngoc Le
Relations
Discrete Structures for Computing
Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
1 Properties of Relations
Contents
2 Combining Relations
Properties of Relations
Combining Relations
Representing Relations
3 Representing Relations
Closures of Relations
Types of Relations
4 Closures of Relations
5 Types of Relations
6.2
Relations
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Types of Relations
L.O.3 Understanding of basic probability and random variables
L.O.3.1 – Define basic probability theory
L.O.3.2 – Explain discrete random variables
6.3
Relations
Introduction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
Function?
6.4
Relations
Relation
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Let A and B be sets. A binary relation (quan hệ hai ngôi) from a
set A to a set B is a set Contents
Properties of Relations
R⊆A×B Combining Relations
Representing Relations
Closures of Relations
• Notations:
Types of Relations
(a, b) ∈ R ←→ aRb
• n-ary relations?
(a1,a2,a3,...an) thuoc R
6.5
Relations
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Let A = {a, b, c} be the set of students, B = {l, c, s, d} be the set
of the available optional courses. We can have relation R that
consists of pairs (a, b), where a is a student enrolled in course b.
Contents
Properties of Relations
Combining Relations
Representing Relations
R = {(a, l), (a, s), (a, g), (b, c), Closures of Relations
Types of Relations
(b, s), (b, g), (c, l), (c, g)}
R l c s g
a x x x
b x x x
c x x
6.6
Relations
Functions as Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
• Is a function a relation?
Properties of Relations
• Yes! Combining Relations
Closures of Relations
R = {(a, b) | b = f (a)} Types of Relations
6.7
Relations
Functions as Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
vi moi A co the co 2 anh tren B Ngoc Le
Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
6.8
Relations
Relations on a Set
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A relation on the set A is a relation from A to A.
Example
Contents
Let A be the set {1, 2, 3, 4}. Which ordered pairs are in the Properties of Relations
relation R = {(a, b) | a divides b} (a là ước số của b)? Combining Relations
Representing Relations
Solution:
Closures of Relations
Types of Relations
R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}
R 1 2 3 4
1 x x x x
2 x x
3 x
4 x
6.9
Relations
Properties of Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Reflexive xRx, ∀x ∈ A
(phản xạ) Contents
Closures of Relations
(phản đối xứng )
Types of Relations
Transitive (xRy ∧ yRz) → xRz, ∀x, y, z ∈ A
(bắc cầu)
bac cau co 2 cach cm : cm k co ele de bac cau V cm tung ele bac cau
6.10
Relations
Example de xet co the tinh chat ko co 2 cach :
Huynh Tuong Nguyen,
C1 : ve hinh Tran Tuan Anh, Nguyen
Ngoc Le
C2 : cm dk luon sai => P->Q dung
C3 : cm dk dung, kl sai => sai
Example C4 : chi ra 1 VD dk dung, kl sai
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)}, Contents
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)}, Properties of Relations
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)}, Combining Relations
Representing Relations
R5 = {(3, 4)}
Closures of Relations
• Reflexive: R3
• Symmetric: R2 , R3 -ve hinh giong phan duoi de giai
• Antisymmetric: R4 , R5 -khi ve chi xet nhung ele co quan he
trong set
• Transitive: R4 , R5
- de thoa man tinh chat thi tat ca cac
ele deu phai thoa man
R5 la bac cau vi :
P->Q voi P la xRy va yRx ; Q là bac cau => P sai ne P->Q dung
6.11
Relations
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
What is the properties of the divides (ước số ) relation on the set
of positive integers? Contents
Properties of Relations
Closures of Relations
• 1 | 2, but 2 - 1: not symmetric Types of Relations
• ∃a, b ∈ Z+ , (a | b) ∧ (b | a) → a = b: antisymmetric
• a | b ⇒ ∃k ∈ Z+ , b = ak; b | c ⇒ ∃l ∈ Z+ , c = bl. Hence,
c = a(kl) ⇒ a | c: transitive
6.12
Relations
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example Contents
What are the properties of these relations on the set of integers: Properties of Relations
Combining Relations
R1 = {(a, b) | a ≤ b} px,pdx, bc Representing Relations
pdx,bc
R2 = {(a, b) | a > b} Closures of Relations
Types of Relations
R3 = {(a, b) | a = b or a = −b} pdx,dx,px,bc
6.13
Relations
Combining Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Closures of Relations
Solution: R1 ∪ R2 , R1 ∩ R2 , R1 − R2 and R2 − R1 . Types of Relations
Example
Let A and B be the set of all students and the set of all courses at
school, respectively. Suppose R1 = {(a, b) | a has taken the course
b} and R2 = {(a, b) | a requires course b to graduate}. What are
the relations R1 ∪ R2 , R1 ∩ R2 , R1 ⊕ R2 , R1 − R2 , R2 − R1 ?
6.14
Relations
Composition of Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Let R be relations from A to B and S be from B to C. Then the
composite (hợp thành) of S and R is Contents
Properties of Relations
Representing Relations
Closures of Relations
Types of Relations
Example
R = {(0, 0), (0, 3), (1, 2), (0, 1)} (0,0) thuoc R bac cau voi (0,0) thuoc
S = {(0, 0), (1, 0), (2, 1), (3, 1)} S => (0,0)
S ◦ R = {(0, 0), (0, 1), (1, 1)} (0,3) thuoc R bac cau (3,1) thuoc S
=> (0,1)
6.15
Relations
Power of Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Let R be a relation on the set A. The powers (lũy thừa)
Rn , n = 1, 2, 3, . . . are defined recursively by
Properties of Relations
Combining Relations
Representing Relations
Example
Closures of Relations
Let R = {(1, 1), (2, 1), (3, 2), (4, 3)}. Find the powers Types of Relations
Rn , n = 2, 3, 4, . . ..
Solution:
R2 = {(1, 1), (2, 1), (3, 1), (4, 2)}
R3 = {(1, 1), (2, 1), (3, 1), (4, 1)}
R4 = {(1, 1), (2, 1), (3, 1), (4, 1)}
···
6.16
Relations
Representing Relations Using Matrices
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition Ngoc Le
Combining Relations
Representing Relations
Example Closures of Relations
Definition
Suppose R is a relation in A = {a1 , a2 , . . . , am }, R can be
represented by the digraph (đồ thị có hướng ) G = (V, E), where Contents
Properties of Relations
V =A Combining Relations
(ai , aj ) ∈ E if (ai , aj ) ∈ R Representing Relations
Closures of Relations
Types of Relations
Example
Given a relation on A = {1, 2, 3, 4},
R = {(1, 1), (1, 3), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (4, 1)}
Draw corresponding digraph.
6.18
Relations
Resulting digraph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1
Contents
Properties of Relations
Combining Relations
Representing Relations
2 4 Closures of Relations
Types of Relations
6.19
Relations
Closure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The closure (bao đóng ) of relation R with respect to property P Contents
Properties of Relations
is the relation S that
3 thuoc tinh da hoc o tren Combining Relations
i. contains R
(ko bao gom phan doi xung) Representing Relations
Types of Relations
iii. is contained in any relation satisfying (i) and (ii).
6.20
Relations
Reflexive Closure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Properties of Relations
{(a, b), (a, c), (b, d), (d, c), (a, a), (b, b), (c, c), (d, d)} Combining Relations
Representing Relations
Closures of Relations
R∪∆ Types of Relations
where
∆ = {(a, a) | a ∈ A}
diagonal relation (quan hệ đường chéo).
6.21
Relations
Reflexive Closure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
6.22
Relations
Symmetric Closure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Let R = {(a, b), (a, c), (b, d), (c, a), (d, e)}
The symmetric closure of R Contents
Properties of Relations
{(a, b), (a, c), (b, d), (c, a), (d, e), (b, a), (d, b), (e, d)} Combining Relations
Representing Relations
Closures of Relations
R ∪ R− Types of Relations
where
R−1 = {(b, a) | (a, b) ∈ R}
inverse relation (quan hệ ngược).
6.23
Relations
Symmetric Closure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
6.24
Relations
Transitive Closure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Contents
Let R = {(a, b), (a, c), (b, d), (d, e)}
Properties of Relations
The transitive closure of R Combining Relations
{(a, b), (a, c), (b, d), (d, e), (a, d), (b, e), (a, e)} Representing Relations
Closures of Relations
Types of Relations
∪∞
n=1 R
n
6.25
Relations
Transitive Closure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
6.26
Relations
Equivalence Relations
Huynh Tuong Nguyen,
Definition Tran Tuan Anh, Nguyen
Ngoc Le
Example (1)
The relation R = {(a, b)|a and b are in the same provinces} is an Contents
a ∼ b. Combining Relations
Representing Relations
Types of Relations
R = {(a, b) | a = b ∨ a = −b}
R is an equivalence relation.
Example (3)
R = {(x, y) | |x − y| < 1}
Is R an equivalence relation? NO do ko co bc
6.27
Relations
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Properties of Relations
Let m be a positive integer with m > 1. Show that the relation Combining Relations
Representing Relations
R = {(a, b) | a ≡ b (mod m)} Closures of Relations
Types of Relations
is an equivalence relation on the set of integers.
6.28
Relations
Equivalence Classes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Let R be an equivalence relation on the set A. The set of all
elements that are related to an element a of A is called the
Contents
equivalence class (lớp tương đương ) of a, denoted by
Properties of Relations
Combining Relations
[a]R = {s | (a, s) ∈ R}
Representing Relations
Closures of Relations
Types of Relations
Example
The equivalence class of “Thủ Đức” for the equivalence relation “in
the same provinces” is { “Thủ Đức”, “Gò Vấp”, “Bình Thạnh”,
“Quận 10”,. . .}
6.29
Relations
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
What are the equivalence classes of 0, 1, 2, 3 for congruence Contents
modulo 4? Properties of Relations
Combining Relations
Solution:
Representing Relations
[0]4 = {..., −8, −4, 0, 4, 8, ...} Closures of Relations
6.30
Relations
Equivalence Relations and Partitions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Theorem
Contents
Let R be an equivalence relation on a set A. These statements for Properties of Relations
elements a and b of A are equivalent: Combining Relations
Closures of Relations
ii [a] = [b] => co it nhat 2 pt giong nhau => giao khac rong Types of Relations
6.31
Relations
Example 1
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Suppose that S = {1, 2, 3, 4, 5, 6}. The collection of sets
A1 = {1, 2, 3}, A2 = {4, 5}, and A3 = {6} forms a partition of S, Contents
because these sets are disjoint and their union is S Properties of Relations
Combining Relations
Representing Relations
Types of Relations
form a partition of S.
6.32
Relations
Example 2
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Divides set of all cities and towns
in Vietnam into set of 64
provinces. We know that:
• there are no provinces with Contents
no cities or towns Properties of Relations
Closures of Relations
• every city is accounted for Types of Relations
Definition
A partition of a Vietnam is a
collection of non-overlapping
non-empty subsets of Vietnam
(provinces) that, together, make
up all of Vietnam.
6.33
Relations
Relation in a Partition
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• We divided based on
relation Contents
Properties of Relations
Representing Relations
Closures of Relations
Types of Relations
6.34
Relations
Partial Order Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
(S, 4).
Example
• (Z, ≥) is a poset
• Let S a set, (P (S), ⊆) is a poset
6.35
Relations
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
Types of Relations
6.36
Relations
Totally Order Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
In the poset (Z+ , |), 3 and 9 are comparable (so sánh được),
because 3 | 9, but 5 and 7 are not, because 5 - 7 and 7 - 5.
Contents
→ That’s why we call it partially ordering. Properties of Relations
Combining Relations
Closures of Relations
If (S, 4) is a poset and every two elements of S are comparable, S
Types of Relations
is called a totally ordered (có thứ tự toàn phần). A totally
ordered set is also called a chain (dây xích).
Example
The poset (Z, ≤) is totally ordered.
6.37
Relations
Maximal & Minimal Elements
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
chi xet nhung ele co quan he R => ele lon nhat la max Ngoc Le
Definition
• a is maximal (cực đại) in the poset (S, 4) if there is no
b ∈ S such that a ≺ b. Contents
Properties of Relations
• a is minimal (cực tiểu) in the poset (S, 4) if there is no
Combining Relations
b ∈ S such that b ≺ a. Representing Relations
Closures of Relations
Types of Relations
Example
Which elements of the poset
({2, 4, 5, 10, 12, 20, 25}, |) are
minimal and maximal?
6.38
Relations
Greatest Element& Least Element
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
co quan he va lon nhat (ko nhat thiet phai co qhe R voi moi ele
=> chi co 1 greatest va 1 least
Definition
• a is the greatest element (lớn nhất) of the poset (S, 4) if
b 4 a for all b ∈ S. Contents
Properties of Relations
• a is the least element (nhỏ nhất) of the poset (S, 4) if Combining Relations
a 4 b for all b ∈ S. Representing Relations
The greatest and least element are unique if it exists. Closures of Relations
Types of Relations
Example
Let S be a set. In the poset (P (S), ⊆), the least element is ∅ and
the greatest element is S.
6.39
Relations
Upper Bound & Lower Bound
Huynh Tuong Nguyen,
Definition ngoai set && co qhe R voi moi ele trong set && lon hon
Tran Tuan Anh, Nguyen
Ngoc Le
Properties of Relations
Combining Relations
Representing Relations
Closures of Relations
6.40
Counting
Chapter 7 Ngoc Le
Counting
Discrete Structures for Computing
Contents
Introduction
Counting Techniques
Pigeonhole Principle
Permutations &
Combinations
Exercises
1 Introduction
Contents
2 Counting Techniques
Introduction
Counting Techniques
Pigeonhole Principle
3 Pigeonhole Principle Permutations &
Combinations
Exercises
5 Exercises
7.2
Counting
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
7.3
Counting
Introduction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Pigeonhole Principle
Permutations &
Combinations
Exercises
7.4
Counting
Applications of Combinatorics
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Number theory
• Probability Contents
Introduction
• Statistics Counting Techniques
Permutations &
• Game theory Combinations
• ...
7.5
Counting
Problems
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
• Number of passwords a hacker should try if he wants to use Introduction
brute force attack Counting Techniques
Permutations &
• Number of operations used by an algorithm Combinations
Exercises
7.6
Counting
Product Rule
Huynh Tuong Nguyen,
Example Tran Tuan Anh, Nguyen
Ngoc Le
Solution
There are two tasks to choose a port: Contents
Counting Techniques
2 picking a port on this router
Pigeonhole Principle
Because there are 32 ways to choose the router and 24 ways to Permutations &
Combinations
choose the port no matter which router has been selected, the
Exercises
number of ports are 32 × 24 = 768 ports.
Example (1)
Two new students arrive at the dorm and there are 12 rooms
available. How many ways are there to assign different rooms to
two students? Contents
Introduction
Counting Techniques
Pigeonhole Principle
Example (2)
Permutations &
Combinations
How many different bit strings of length seven are there?
Exercises
Example (3)
How many one-to-one functions are there from a set with m
elements to one with n elements?
7.8
Counting
Sum Rule
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
A student can choose a project from one of three fields:
Information system (32 projects), Software Engineering (12
Contents
projects) and Computer Science (15 projects). How many ways are
Introduction
there for a student to choose?
Counting Techniques
Solution: 32 + 12 + 15 Pigeonhole Principle
Permutations &
Combinations
Definition (Sum Rule (Luật cộng))
Exercises
7.9
Counting
Using Both Rules
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
In a computer language, the name of a variable is a string of one
or two alphanumeric characters, where uppercase and lowercase
letters are not distinguished. Moreover, a variable name must
begin with a letter and must be different from the five strings of
two characters that are reserved for programming use. How many Contents
Introduction
different variables names are there in this language?
Counting Techniques
Pigeonhole Principle
Solution Permutations &
Combinations
Let V equal to the number of different variable names.
Exercises
Let V1 be the number of these that are one character long, V2 be
the number of these that are two characters long. Then, by sum
rule, V = V1 + V2 .
Note that V1 = 26, because it must be a letter. Moreover, there
are 26 · 36 strings of length two that begin with a letter and end
with an alphanumeric character. However, five of these are
excluded, so V2 = 26 · 36 − 5 = 931. Hence V = V1 + V2 = 957
different names for variables in this language.
7.10
Counting
Inclusion-Exclusion
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
How many bit strings of length eight either start with a 1 bit or
end with the two bits 00?
Contents
Introduction
Counting Techniques
Solution
Pigeonhole Principle
• Bit string of length eight that begins with a 1 is 27 = 128 Permutations &
Combinations
ways Exercises
7.11
Counting
Inclusion-Exclusion
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Introduction
|A ∪ B| = |A| + |B| − |A ∩ B| Counting Techniques
Pigeonhole Principle
Permutations &
Combinations
Exercises
7.12
Counting
Inclusion-Exclusion
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
|A ∪ B ∪ C| =??? Introduction
Counting Techniques
Pigeonhole Principle
Permutations &
Combinations
Exercises
7.13
Counting
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
they liked Arsenal, 91 indicated that they liked Chelsea and 91 Introduction
indicated that they liked MU. Of the students surveyed, 9 liked Counting Techniques
only Arsenal, 10 liked only Chelsea, 12 liked only MU and 40 liked Pigeonhole Principle
Permutations &
all three clubs. How many of the student surveyed liked both MU Combinations
7.14
Counting
Pigeonhole Principle
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Introduction
Counting Techniques
Pigeonhole Principle
Permutations &
Combinations
Exercises
7.15
Counting
Examples
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Example (1) Ngoc Le
Among any group of 367 people, there must be at least two with
the same birthday.
Because there are only 366 possible birthdays.
Contents
Example (2) Introduction
Counting Techniques
In any group of 27 English words, there must be at least two that
Pigeonhole Principle
begin with the same letter.
Permutations &
Combinations
Because there are 26 letters in the English alphabet. Exercises
7.16
Counting
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Prove that if seven distinct numbers are selected from
{1, 2, . . . , 11}, then some two of these numbers sum to 12.
Contents
Solution Introduction
Counting Techniques
1 Pigeons: seven numbers from {1, 2, . . . , 11} Pigeonhole Principle
2 Pigeonholes: corresponding to six sets, {1, 11}, {2, 10}, Permutations &
Combinations
{3, 9}, {4, 8}, {5, 7}, {6} Exercises
7.17
Counting
Examples – Permutations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
How many ways can we arrange three students to stand in line for
a picture?
Contents
Introduction
Counting Techniques
Pigeonhole Principle
Permutations &
Number of choices: 6 = 3! Combinations
Exercises
7.18
Counting
Permutations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A permutation (hoán vị) of a set of distinct objects is an ordered
arrangement of these objects.
An ordered arrangement of r elements of a set is called an
r-permutation (hoán vị chập r). Contents
Introduction
n! Counting Techniques
P (n, r) = Pigeonhole Principle
(n − r)!
Permutations &
Combinations
Exercises
Example
How many ways are there to select a first-prize winner, a
second-prize winner, and a third-prize winner from 100 different
people who have entered a contest?
7.19
Counting
Examples – Combinations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Introduction
Counting Techniques
Pigeonhole Principle
Permutations &
Combinations
Exercises
Number of choices: 6
7.20
Counting
Combinations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition (Combinations)
An r-combination (tổ hợp chập r) of elements of a set is an
unordered selection of r elements from the set. Thus, an
r-combination is simply a subset of the set with r elements.
Contents
n n! Introduction
C(n, r) = = Counting Techniques
r r!(n − r)!
Pigeonhole Principle
Permutations &
Combinations
Example Exercises
22!
C(22, 11) = = 705432
11!11!
7.21
Counting
Exercises – Permutations with Repetition
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Permutations &
and 11 in CE department. How many ways are there to select Combinations
a defend committee if the committee is to consist of three Exercises
7.22
Counting
Permutations with Repetition
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
How many strings of length r can be formed from the English Contents
alphabet? Introduction
By product rule, we see that there are 26r strings of length r. Counting Techniques
Pigeonhole Principle
Permutations &
Combinations
Theorem Exercises
7.23
Counting
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Question: How many ways we can choose 3 students from the Introduction
Counting Techniques
faculties of Computer Science, Electrical Engineering and
Pigeonhole Principle
Mechanical Engineering?
Permutations &
Combinations
Exercises
7.24
Counting
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Counting Techniques
CCM EEM
Pigeonhole Principle
CEE EMM
Permutations &
CMM MMM Combinations
Exercises
7.25
Counting
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Permutations &
Combinations
Exercises
7.26
Counting
Combinations with Repetition
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Theorem
There are C(n + r − 1, r) r-combinations from a set with n
Contents
elements when repetition of elements is allowed.
Introduction
Counting Techniques
Example Pigeonhole Principle
Exercises
x1 + x2 + x3 = 11
7.27
Counting
Examples
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Introduction
Counting Techniques
Pigeonhole Principle
Permutations &
MISSISSIPPI ≡ MISSISSIPPI Combinations
Exercises
7.28
Counting
Permutations with Indistinguishable Objects
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Theorem
The number of different permutations of n objects, where there
are n1 indistinguishable objects of type 1, n2 indistinguishable Contents
Counting Techniques
n! Pigeonhole Principle
Exercises
Example
How many permutations are there of MISSISSIPPI?
7.29
Counting
Hãng hàng không
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
A) 2 Counting Techniques
Pigeonhole Principle
B) 4
Permutations &
C) 5 Combinations
Exercises
D) 6
E) 7
F) Các chọn lựa khác đều sai
7.30
Counting
Quần vợt
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Hai tuyển thủ quần vợt nữ thi đấu cùng nhau trong tối đa 3 hiệp.
Tuyển thủ nào thắng ít nhất hai trận thì sẽ thắng giải. Mỗi hiệp
đấu không bao giờ xảy ra tình huống hai đội hòa nhau. Có bao Contents
Counting Techniques
A) 4 Pigeonhole Principle
B) 5 Permutations &
Combinations
C) 6 Exercises
D) 7
E) Các chọn lựa khác đều sai
7.31
Counting
Mã hóa
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Permutations &
Có bao nhiêu chuỗi bit có độ dài 100 với số bit 0 và bit 1 như Combinations
nhau? Exercises
100
A) 2
100
B) 50
50
C) 2
D) 1001
E) Các chọn lựa khác đều sai
7.32
Counting
Bút màu
Huynh Tuong Nguyen,
Trong lúc đến trường, hai bạn An và Bão đếm số lượng bút bi Tran Tuan Anh, Nguyen
Ngoc Le
màu đem theo. Tổng cộng 10 cây viết gồm có hai màu: xanh (X)
và tím (T).
Đặt XA , TA lần lượt biểu diễn số lượng bút xanh và tím của bạn
An.
Và đặt XB , TB lần lượt biểu diễn số lượng bút xanh và bút tím
của bạn Bão. Contents
Bạn An nhận thấy rằng số bút màu xanh của An lớn hơn hoặc Introduction
bằng 2 lần số bút màu tím của anh ta. Bạn Bão có số bút màu Counting Techniques
Pigeonhole Principle
xanh lớn hơn hoặc bằng 2 lần số bút màu xanh của bạn An.
Permutations &
Hỏi có bao nhiêu trường hợp có thể có của bộ giá trị (XA , TA )? Combinations
A) 2 Exercises
B) 4
C) 6
D) 8
E) nhiều hơn 10
F) Các chọn lựa khác đều sai
Bạn Bão không có bút màu tím. Hỏi có bao nhiêu trường hợp có
thể có của bộ giá trị (XA , TA , XB , TB )?
A) 2
B) 5 7.33
Counting
Tiệc
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Một buổi tiệc nhỏ có 2 bàn tròn với số lượng khách là n (n ≥ 3).
Bàn thứ nhất có k ghế ngồi và bàn thứ hai có n − k ghế ngồi
(k ≥ 3, n − k ≥ 3). Các ghế ngồi đều được đánh số khác nhau từ
1, 2, . . . n. Trong n vị khách thì có 3 vị khách đặc biệt là X, Y, Z Contents
cần được sắp xếp ngồi cạnh nhau (theo một thứ tự nào đó). Hỏi Introduction
có bao nhiêu cách sắp xếp hợp lệ các vị khách theo số ghế ? Counting Techniques
Pigeonhole Principle
A) 6k!(k − 3)!(n − k)! + 6(n − k)(n − k − 3)!k!
Permutations &
B) 6(n − k)(n − k − 3)!k! Combinations
Exercises
C) 6k!(k − 3)!(n − k)!
D) 6k!(n − k)!
E) 6n(n − 3)!
F) Các chọn lựa khác đều sai
7.34
Counting
Tiệc
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Một buổi tiệc nhỏ có 2 bàn tròn với số lượng khách là n (n ≥ 3).
Bàn thứ nhất có k ghế ngồi và bàn thứ hai có n − k ghế ngồi
(k ≥ 3, n − k ≥ 3). Các ghế ngồi đều được đánh số khác nhau từ
1, 2, . . . n. Trong n vị khách thì có 3 vị khách đặc biệt là X, Y, Z Contents
cần được sắp xếp ngồi cạnh nhau (theo một thứ tự nào đó). Hỏi Introduction
có bao nhiêu cách sắp xếp hợp lệ các vị khách theo số ghế ? Counting Techniques
Pigeonhole Principle
A) 6k!(k − 3)!(n − k)! + 6(n − k)(n − k − 3)!k!
Permutations &
B) 6(n − k)(n − k − 3)!k! Combinations
Exercises
C) 6k!(k − 3)!(n − k)!
D) 6k!(n − k)!
E) 6n(n − 3)!
F) Các chọn lựa khác đều sai
7.35
Counting
Con rắn
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Một phép hoán vị (x1 , x2 , . . . , xn ) của các số {1, 2, . . . , n} được Ngoc Le
gọi là con rắn (có độ dài n) nếu x1 < x2 > x3 < x4 . . ..
Ví dụ:
n = 2, ta chỉ có 1<2 , số con rắn là 1,
n = 3, 1<3>2
, số con rắn là 2,
2<3>1
n = 4, 1<3>2<4
Contents
Introduction
1<4>2<3
Counting Techniques
2<3>1<4 , số con rắn là 5. Pigeonhole Principle
2<4>1<3
Permutations &
3<4>1<2 Combinations
Exercises
Tìm số con rắn có độ dài 5.
A) 12
B) 14
C) 16
D) 17
E) 20
F) Các chọn lựa khác đều sai
7.36
Counting
Pokemon
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
ngồi sao cho Pikachu và Meowth không ngồi cạnh nhau và cũng Introduction
Pigeonhole Principle
A) 720
Permutations &
B) 522 Combinations
Exercises
C) 480
D) 384
E) 120
F) Các chọn lựa khác đều sai
7.37
Counting
Giải đấu vật
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Trong một giải đấu đấu vật để xác định một nhà vô địch thế giới,
101 vận động viên từ khắp các nước đến tham dự. Hỏi cần tổ chức
bao nhiêu trận đấu biết rằng mỗi trận đấu sẽ phân biệt thắng thua Contents
giữa hai vận động viên và người thua sẽ bị loại ngay khỏi giải đấu? Introduction
A) 1 Counting Techniques
Pigeonhole Principle
B) 70
Permutations &
C) 100 Combinations
Exercises
D) 99
E) Không thể xác định con số chính xác
F) Các chọn lựa khác đều sai
7.38
Counting
Nam nữ
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Lớp của bạn An có 17 học sinh nam và 19 học sinh nữ. Nhân dịp
sinh nhật của bạn An, các bạn trong lớp đều chuẩn bị quà tặng.
Mỗi bạn nam của lớp làm 4 mô hình giấy và mỗi bạn nữ xếp 3
Contents
hoặc 5 ngôi sao may mắn để tặng.
Introduction
Biết số mô hình giấy và số ngôi sao may mắn bằng nhau, hỏi bạn
Counting Techniques
An là nam hay nữ? Pigeonhole Principle
C) Nam
D) Nữ
E) Các chọn lựa khác đều sai
7.39
Counting
Chia quà
Huynh Tuong Nguyen,
Xét bài toán chia k phần quà hoàn toàn giống nhau cho n sinh Tran Tuan Anh, Nguyen
Ngoc Le
viên CSE-HCMUT sao cho mỗi sinh viên phải được ít nhất một
phần quà và các phần quà phải được phân phối hết.
Với k = 6 và n = 2, hỏi có bao nhiêu cách chia phần quà?
A) 3
B) 4
Contents
C) 5
Introduction
D) 6
Counting Techniques
E) 7 Pigeonhole Principle
F) 20 Permutations &
Combinations
G) Các chọn lựa khác đều sai Exercises
Việc lưu trữ tài khoản các đồng tiền mã hóa (crypto-currencies) ở
một ví thường được quản lý bới một cơ chế bảo mật Passphrase.
Contents
Với người dùng, thay vì nhớ mã code hoặc mật khẩu của từng tài
Introduction
khoản, thì chỉ cần nhớ một passphrase riêng có thể truy xuất được
Counting Techniques
bất kỳ tài khoản nào trong ví riêng của mình. Pigeonhole Principle
Nhìn góc độ hệ thống, từ mã passphrase, sẽ có một cơ chế xác Permutations &
định số tài khoản của người dùng. Và để đảm bảo đủ tính bảo Combinations
Exercises
mật, trên thực tế, người ta dùng passphrase bao gồm 12 từ tiếng
Anh có nghĩa.
Hỏi có bao nhiêu khả năng xảy ra?
7.41
Discrete Probability
Chapter 8 Ngoc Le
Discrete Probability
Discrete Structures for Computing
Contents
Introduction
Randomness
Probability
Probability Rules
Random variables
Probability Models
Geometric Model
Binomial Model
1 Introduction
Randomness
Contents
2 Probability
Introduction
Randomness
Probability
3 Probability Rules
Probability Rules
Random variables
Probability Models
4 Random variables Geometric Model
Binomial Model
5 Probability Models
Geometric Model
Binomial Model
8.2
Discrete Probability
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Random variables
L.O.3 Understanding of basic probability and random variables
Probability Models
L.O.3.1 – Define basic probability theory Geometric Model
L.O.3.2 – Explain discrete random variables Binomial Model
8.3
Discrete Probability
Motivations
Huynh Tuong Nguyen,
• Gambling Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Introduction
Randomness
Probability
• Real life problems
Probability Rules
Random variables
Probability Models
Geometric Model
Binomial Model
Probability Models
In the long run, they are predictable and have relative frequency
(fraction of times that the event occurs over and over and over).
8.5
Discrete Probability
Terminology
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Introduction
Randomness
Probability
Probability Rules
Random variables
Probability Models
• Experiment (thí nghiệm): a procedure that yields one of a Geometric Model
8.6
Discrete Probability
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example (1)
Experiment: Rolling a die. What is the sample space?
Answer: {1, 2, 3, 4, 5, 6}
Contents
Introduction
Probability
Experiment: Rolling two dice. What is the sample space? Probability Rules
Probability Models
• The total number? Geometric Model
Which is better?
The latter one, because they are equally likely outcomes
8.7
Discrete Probability
The Law of Large Numbers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The Law of Large Numbers (Luật số lớn) states that the long-run
relative frequency of repeated independent events gets closer and Contents
Probability Rules
Example Random variables
Probability Models
Do you believe that the true relative frequency of Head when you Geometric Model
Let’s try!
8.8
Discrete Probability
Be Careful!
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example Contents
I had 8 children, all of them are girls. Thanks to LLN (!?), there Introduction
Randomness
are high possibility that the next one will be a boy. Probability
(Overpopulation!!!) Probability Rules
Random variables
Probability Models
Example Geometric Model
Binomial Model
I’m playing Bầu cua tôm cá, the fish has not appeared in recent 5
games, it will be more likely to be fish next game. Thus, I bet all
my money in fish. (Sorry, you lose!)
8.9
Discrete Probability
Probability
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The probability (xác suất) of an event E of a finite nonempty
sample space of equally likely outcomes S is:
Contents
|E| Introduction
p(E) = . Randomness
|S|
Probability
Probability Rules
Random variables
• Note that E ⊆ S so 0 ≤ |E| ≤ |S|
Probability Models
• 0 ≤ p(E) ≤ 1 Geometric Model
Binomial Model
• 0 indicates impossibility
• 1 indicates certainty
8.10
Discrete Probability
Examples
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example (1)
What is the probability of getting a Head when tossing a coin?
Answer:
• There are |S| = 2 possible outcomes
• Getting a Head is |E| = 1 outcome, so Contents
Introduction
p(E) = 1/2 = 0.5 = 50% Randomness
Probability
Probability Rules
Example (2)
Random variables
Example (3)
We toss a coin 6 times. What is probability of H in 6th toss, if all
the previous 5 are T?
Answer: Contents
Probability
Example (4) Probability Rules
Random variables
Which is more likely:
Probability Models
• Rolling an 8 when 2 dice are rolled? Geometric Model
Binomial Model
• Rolling an 8 when 3 dice are rolled?
Answer:
Two dice: 5/36 ≈ 0.139
Three dice: 21/216 ≈ 0.097
8.12
Discrete Probability
Formal Probability
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Rule 1 Ngoc Le
0 ≤ p(E) ≤ 1
Contents
Introduction
Rule 2: Something has to happen rule Randomness
The probability of the set of all possible outcomes of a trial must Probability
be 1. Probability Rules
Random variables
p(S) = 1
Probability Models
Geometric Model
Binomial Model
p(E) = 1 − p(E)
8.13
Discrete Probability
Examples
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
What is the probability of NOT drawing a heart card from 52 deck
Contents
cards?
Introduction
Answer: Randomness
Probability
Let E be the event of getting a heart from 52 deck cards. We
Probability Rules
have: Random variables
p(E) = 13/52 = 1/4 Probability Models
By the compliment rule, the probability of NOT getting a heart Geometric Model
Binomial Model
card is:
p(E) = 1 − p(E) = 3/4
8.14
Discrete Probability
Formal Probability
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Introduction
p(E1 ∪ E2 ) = p(E1 ) + p(E2 ) − p(E1 ∩ E2 ) Randomness
Probability
Probability Rules
• If E1 ∩ E2 = ∅: They are disjoint, which means they can’t Random variables
occur together Probability Models
8.15
Discrete Probability
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example (1)
If you choose a number between 1 and 100, what is the probability
that it is divisible by either 2 or 5?
Contents
Short Answer: Introduction
50 20 10 3
100 + 100 − 100 = 5 Randomness
Probability
Probability Rules
Probability Models
There are a survey that about 45% of VN population has Type O Geometric Model
blood, 40% type A, 11% type B and the rest type AB. What is the Binomial Model
8.16
Discrete Probability
Conditional Probability (Xác suất có điều kiện)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Introduction
Randomness
Probability
Probability Rules
Random variables
Probability Models
Geometric Model
Binomial Model
8.17
Discrete Probability
Conditional Probability
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
p(E | F ) = Probability of event E given that event F has
occurred. Contents
Introduction
Randomness
Probability
General Multiplication Rule
Probability Rules
Random variables
Probability Models
= p(F ) × p(E | F )
8.18
Discrete Probability
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
What is the probability of drawing a red card and then another red
card without replacement (không hoàn lại)? Contents
Introduction
Randomness
Solution Probability
Probability Rules
E: the event of drawing the first red card
Random variables
F : the event of drawing the second red card
Probability Models
p(E) = 26/52 = 1/2 Geometric Model
So the event of drawing a red card and then another red card is
p(E ∩ F ) = p(E) × p(F | E) = 1/2 × 25/51 = 25/102
8.19
Discrete Probability
Independence
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Events E and F are independent (độc lập) whenever
p(E | F ) = p(E)
Contents
• The outcome of one event does not influence the probability Introduction
Randomness
Random variables
• If E and F are independent
Probability Models
Geometric Model
Disjoint 6= Independence
Disjoint events cannot be independent. They have no outcomes in
common, so knowing that one occurred means the other did not.
8.20
Discrete Probability
Bayes’s Theorem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
If we know that the probability that a person has tuberculosis
(TB) is p(TB) = 0.0005. Contents
We also know p(+|TB) = 0.999 and p(−|TB) = 0.99. Introduction
Probability
Probability Rules
Random variables
Theorem (Bayes’s Theorem) Probability Models
Geometric Model
Binomial Model
p(E | F )p(F )
p(F | E) =
p(E | F )p(F ) + p(E | F )p(F )
8.21
Discrete Probability
Expected Value: Center
Huynh Tuong Nguyen,
An insurance company charges $50 a year. Can company make a Tran Tuan Anh, Nguyen
Ngoc Le
profit? Assuming that it made a research on 1000 people and have
following table:
Outcome Payroll Probability
x p(X = x)
Contents
1
Death 10,000 1000 Introduction
Randomness
2
Disability 5000 1000 Probability
• X is a discrete random variable (biến ngẫu nhiên rời rạc) Probability Models
Geometric Model
The company expects that they have to pay each customer: Binomial Model
1 2 997
E(X) = $10, 000( ) + $5000( ) + $0( ) = $20
1000 1000 1000
• Variance P
(phương sai)
V (X) = (x − E(X))2 · p(X = x) Contents
Comment
The company expects to pay out $20, and make $30. However,
the standard deviation of $386.78 indicates that it’s no sure thing.
That’s pretty big spread (and risk) for an average profit of $20.
8.23
Discrete Probability
Bernoulli Trials
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Some people madly drink Coca-Cola, hoping to find a ticket to see
Big Bang. Let’s call tearing a bottle’s label trial (phép thử ):
• There are only possible outcomes (congrats or good luck) Contents
Introduction
• The probability of success, p, is the same on every trial, say Randomness
0.06 Probability
Probability Rules
• The trials are independent. Finding a ticket in the first bottle
Random variables
does not change what might happen in the second one. Probability Models
Geometric Model
Binomial Model
• Bernoulli Trials
• Another examples: tossing a coin many times, results of
testing TB on many patients, . . .
8.24
Discrete Probability
Geometric Model (Mô hình hình học)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Definition (Geometric probability model: Geom(p)) Introduction
Randomness
p = probability of success (q = 1 − p = probability of failure) Probability
X = number of trials until the first success occurs Probability Rules
Random variables
p(X = x) = q x−1 p Probability Models
Geometric Model
1 Binomial Model
Expected value: µ = p q
q
Standard deviation: σ = p2
8.25
Discrete Probability
Geometric Model: Example
Huynh Tuong Nguyen,
Example Tran Tuan Anh, Nguyen
Ngoc Le
Solution Introduction
Randomness
Probability Models
Geometric Model
Binomial Model
P (X ≤ 4) = P (X = 1) + P (X = 2) + P (X = 3) + P (X = 4)
= (0.06) + (0.94)(0.06) + (0.94)2 (0.06)
+(0.94)3 (0.06)
≈ 0.2193
Introduction
Probability
n = number of trials Probability Rules
Expected value: µ = np
√
Standard deviation: σ = npq
8.27
Discrete Probability
Binomial Model: Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Example Ngoc Le
Suppose you buy 20 Coca-Cola bottles. What are the mean and
standard deviation of the number of winning bottles among them?
What is the probability that there are 2 or 3 tickets?
Solution Contents
Introduction
Let X = number of tickets among n = 20 bottles Randomness
Probability Models
P (X = 2 or 3) = P (X = 2) + P (X = 3) Geometric Model
Binomial Model
20 20
= (0.06)2 (0.94)18 + (0.06)3 (0.94)17
2 3
≈ 0.2246 + 0.0860 = 0.3106
Chapter 9 Ngoc Le
Introduction to Graphs
Discrete Structures for Computing
Contents
Graph definitions
Terminology
Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
1 Graph definitions
Terminology
Special Graphs
Contents
Graph definitions
Exercise
3 Exercise Graph
9.2
Introduction to Graphs
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
9.3
Introduction to Graphs
Motivations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
a graph.
9.4
Introduction to Graphs
Graph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
1 3 1 3 Graph
Bipartie graph
Isomorphism
9.5
Introduction to Graphs
Undirected Graph (Đồ thị vô hướng)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.6
Introduction to Graphs
Undirected Graph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph definitions
An unordered pair of vertices {u, v} are called multiplicity m (bội Terminology
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.7
Introduction to Graphs
Undirected Graph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.8
Introduction to Graphs
Directed Graph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
A directed edge start at u and end at v is denoted as (u, v). Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.9
Introduction to Graphs
Terminologies For Undirected Graph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Neighborhood
In an undirected graph G = (V, E),
• two vertices u and v ∈ V are called adjacent (liền kề ) if they
are end-points (điểm đầu mút) of edge e ∈ E, and Contents
Representing Graphs
and Graph
Isomorphism
The degree of a vertex Representing Graphs
Graph Isomorphism
The degree of a vertex (bậc của một đỉnh), denoted by deg(v) is Exercise
the number of edges incident with it, except that a loop Graph
Bipartie graph
contributes twice to the degree of that vertex. Isomorphism
Graph definitions
Terminology
Special Graphs
a f e g e d Representing Graphs
and Graph
G H Isomorphism
Representing Graphs
Graph Isomorphism
Solution Exercise
Graph
Representing Graphs
(Note that this applies even if multiple edges and loops are and Graph
Isomorphism
present.) Representing Graphs
Graph Isomorphism
Exercise
Graph
9.12
Introduction to Graphs
Prove that ... hw Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
...
If the number of vertices in an undirected graph is an odd number,
then there exists an even-degree vertex. Contents
Graph definitions
... Terminology
Special Graphs
... Exercise
Graph
If the number of vertices in an undirected graph is an even Bipartie graph
number, then the number of vertices with even degree is even. Isomorphism
9.13
Introduction to Graphs
Terminologies for Directed Graph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Neighborhood
In an directed graph G = (V, E),
• u is said to be adjacent to (nối tới) v and v is said to be
adjacent from (được nối từ) u if (u, v) is an arc of G, and
• u is called initial vertex (đỉnh đầu) of (u, v) Contents
Representing Graphs
and Graph
Isomorphism
The degree of a vertex Representing Graphs
Graph Isomorphism
In a graph G with directed edges: Exercise
Theorem Contents
Exercise
Graph
Bipartie graph
Isomorphism
9.18
Introduction to Graphs
Complete Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph definitions
Terminology
Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
K5 K4
9.20
Introduction to Graphs
Cycles
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph definitions
Terminology
Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
C5 C4
9.21
Introduction to Graphs
Wheels
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
W5 W4
9.22
Introduction to Graphs
n-cube
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
0 1 Exercise
Graph
Bipartie graph
00 01 000 001 Isomorphism
Q1 Q2 Q3
Qn is bipartite
Graph definitions
• Star, ring, hybrid Terminology
Representing Graphs
• Linear array and Graph
Isomorphism
• Mesh network Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.24
Introduction to Graphs
Exercise hw
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise (5)
Give the number of edges in function of number of vertices in a
complete graph Kn . (n-1)*n/2
Graph definitions
Give an undirected simple graph G = (V, E) with |V | = n, show Terminology
Representing Graphs
a ∀v ∈ V , deg(v) < n, and Graph
Isomorphism
b there does not exist simultaneously both a vertex of degree 0 Representing Graphs
Graph Isomorphism
and a vertex of degree (n − 1) with n ≥ 2, Exercise
c deduce that there are at least two vertices of the same degree. Graph
Bipartie graph
0+1+2+..+n-1 Isomorphism
Exercise (7)
Is it possible that each person has exactly 3 friends in the same
group of 9 people ? 3*9=27 ko chia het cho 2
9.25
Introduction to Graphs
Bipartite Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A simple graph G is called bipartite (đồ thị phân đôi) if its vertex
set V can be partitioned into two disjoint sets V1 and V2 such that
every edge in the graph connects a vertex in V1 and a vertex in V2
(so that no edge in G connects either two vertices in V1 or two
Contents
vertices in V2 ) neu do thi con la tam giac thi ko phan doi Graph definitions
Terminology
Special Graphs
Example
Representing Graphs
and Graph
C6 is bipartite Cn is bipartie if n is even Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.29
Introduction to Graphs
Complete Bipartite Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A complete bipartite Km,n is a graph that
• has its vertex set partitioned into two subsets of m and n
vertices, respectively,
Contents
• with an edge between two vertices iff one vertex is in the first Graph definitions
subset and the other is in the second one Terminology
Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
K3,3
moi dinh dc noi voi all dinh o subset kia
9.30
Introduction to Graphs
Bipartite graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• C6
• Cn
• K3 Contents
• Kn Graph definitions
Terminology
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.31
Introduction to Graphs
New Graph From Old
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A subgraph (đồ thị con) of a graph G = (V, E) is a graph
H = (W, F ) where W ⊆ V and F ⊆ E.
Contents
Definition Graph definitions
Exercise
Graph
Bipartie graph
Isomorphism
G1 G2 G1 ∪ G2
9.32
Introduction to Graphs
Planar Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Graph definitions
Terminology
Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.33
Introduction to Graphs
Planar Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• A graph is called planar (phẳng ) if it can be drawn in the
plane without any edges crossing.
• Such a drawing is called planar representation (biểu diễn
Contents
phẳng ) of the graph. Graph definitions
Terminology
Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
K4 K4 with no crossing
9.34
Introduction to Graphs
Important Corollaries
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Corollary
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
K3,3
Non-planar
K5
Non-planar
9.35
Introduction to Graphs
Elementary Subdivision
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• Given a planar graph G, an elementary subdivision (phân chia
sơ cấp) is removing an edge {u, v} and adding a new vertex
w together with edges {u, w} and {w, v}. Contents
homeomorphic (đồng phôi) if they can obtained from the Special Graphs
Exercise
Graph
Bipartie graph
Isomorphism
9.36
Introduction to Graphs
Kuratowski’s Theorem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Theorem
A graph is nonplanar iff it contains a subgraph homeomorphic to
K3,3 or K5 .
Contents
Graph definitions
Terminology
a Special Graphs
Representing Graphs
and Graph
f f d Isomorphism
c j Representing Graphs
e b
j g Graph Isomorphism
a g Exercise
Graph
i h
e Bipartie graph
Isomorphism
i h
d c
9.37
Introduction to Graphs
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
• Is K4 planar?
• Is Q3 planar?
Graph definitions
Terminology
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
010 011 Exercise
Graph
Bipartie graph
Isomorphism
000 001
K4 Q3
9.38
Introduction to Graphs
Adjacency Lists (Danh sách kề)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
d c, e d c, e Graph definitions
Terminology
e a, c, d e b, c, d Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.39
Introduction to Graphs
Adjacency Matrices
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Adjacency matrix (Ma trận kề ) AG of G = (V, E)
• Dimension |V | × |V |
• Matrixelements
1 if (vi , vj ) ∈ E Contents
aij =
0 otherwise Graph definitions
a b c d
Graph Isomorphism
Exercise
a 0 1 1 1 Graph
b 1 0 1 0 Bipartie graph
Isomorphism
c 1 1 0 0
d 1 0 0 0
c d
9.40
Introduction to Graphs
Examples
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Give the graph defined by the following adjacency matrix
Contents
Graph definitions
A B C D E Terminology
Special Graphs
Representing Graphs
A
0 0 1 1 0
and Graph
Isomorphism
B
0 1 0 1 0
Representing Graphs
C
1 0 0 1 0
Graph Isomorphism
D
1 1 1 0 1
Exercise
Graph
E 0 0 0 1 0 Bipartie graph
Isomorphism
9.41
Introduction to Graphs
Adjacency Matrices
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Give the directed graph defined by the following adjacency matrix
Contents
Graph definitions
A B C D E Terminology
Special Graphs
Representing Graphs
A
1 0 1 1 0
and Graph
Isomorphism
B
0 0 0 0 0
Representing Graphs
C
1 0 0 0 0
Graph Isomorphism
D
1 1 1 0 1
Exercise
Graph
E 1 0 0 0 0 Bipartie graph
Isomorphism
9.42
Introduction to Graphs
Incidence Matrices
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Incidence matrix (ma trận liên thuộc) MG of G = (V, E)
• Dimension |V | × |E|
• Matrix
elements
1 if ej is incident with vi Contents
mij =
0 otherwise Graph definitions
Terminology
Special Graphs
Representing Graphs
a e2 b and Graph
Isomorphism
Representing Graphs
e1 e2 e3 e4
Graph Isomorphism
Exercise
a 1 1 1 0 Graph
e1 b 0 1 0 1 Bipartie graph
e4 e3 Isomorphism
c 1 0 0 1
d 0 0 1 0
c d
9.43
Introduction to Graphs
Examples
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Give incidence matrix according to the following graph
Contents
F Graph definitions
Terminology
Special Graphs
B C Representing Graphs
and Graph
Isomorphism
Representing Graphs
A Graph Isomorphism
Exercise
Graph
E D Bipartie graph
Isomorphism
G
9.44
Introduction to Graphs
Graph Isomorphism
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are isomorphic (đẳng cấu) if
there is a one-to-one function f from V1 to V2 with the property
that a and b are adjacent in G1 iif f (a) and f (b) are adjacent in Contents
G2 , for all a and b in V1 . Such a function f is called an Graph definitions
isomorphism (một đẳng cấu). Terminology
Special Graphs
(i.e. there is a one-to-one correspondence between vertices of the Representing Graphs
two graphs that preserves the adjacency relationship.) and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
u1 u2 v1 v2
Isomorphism function f : U −→ Exercise
Graph
f (u3 ) = v3 f (u4 ) = v2
u3 u4 v3 v4
9.45
Introduction to Graphs
Bipartie graph
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Graph definitions
Terminology
Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.46
Introduction to Graphs
Isomorphism ?
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Graph definitions
Terminology
Special Graphs
Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
Exercise
Graph
Bipartie graph
Isomorphism
9.47
Introduction to Graphs
Isomorphism?
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
A
A B Contents
B Graph definitions
Terminology
Special Graphs
C F C Representing Graphs
and Graph
Isomorphism
Representing Graphs
Graph Isomorphism
D E D Exercise
Graph
G2
F E Bipartie graph
Isomorphism
G1
9.48
Introduction to Graphs
Isomorphism?
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
A1 A2 B2
Contents
Graph definitions
Terminology
D1 E1 E2 F2 Special Graphs
Representing Graphs
and Graph
Isomorphism
F1 Representing Graphs
Graph Isomorphism
Exercise
C1 B1 D2 C2 Graph
G1 G2 Bipartie graph
Isomorphism
9.49
Introduction to Graphs
Isomorphism
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1 0 0 1 1 0 0 Graph definitions
Terminology
1 1 0 1 0 0 Special Graphs
Representing Graphs
0 1 0 1 0 1 1 1 and Graph
1 0 Isomorphism
0 1 1 0 0 1 Representing Graphs
2
0 0 0 1 1 0 0 1 Graph Isomorphism
1 1 1 0 1 1 1 0 Exercise
Graph
0 1 1 0 0 1 0 1 Bipartie graph
Isomorphism
1 0 0 1 1 0 0 0
3
1 0 0 1 0 0 0 1
0 1 1 0 1 0 1 0
9.50
Introduction to Graphs
Isomorphism
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1 1 0 0 1 1 Special Graphs
Representing Graphs
1 1 0 0 0 0 1 0 0 1 and Graph
Isomorphism
• 1 0 1 0 1 0 1 1 1 0
Representing Graphs
Graph Isomorphism
0 0 0 1 1 1 0 0 1 0
Exercise
0 1 1 1 0 1 0 1 0 1 Graph
Bipartie graph
• Extend the definition of isomorphism of simple graphs to Isomorphism
9.51
Graph connectivity
Chapter 10 Ngoc Le
Graph connectivity
Discrete Structures for Computing
Contents
Connectivity
Paths and Circuits
Graph Coloring
Contents
Connectivity
Some slides about Euler and Hamilton circuits are created by Paths and Circuits
Chung Ki-hong and Hur Joon-seok from KAIST. Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits
Graph Coloring
10.2
Graph connectivity
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
L.O.2.2 – Use proving methods: direct, contrapositive, induction Euler and Hamilton
Paths
L.O.2.3 – Explain problem modeling using discrete structures
Euler Paths and Circuits
Hamilton Paths and Circuits
L.O.3 Understanding of basic probability and random variables Shortest Path Problem
L.O.3.1 – Define basic probability theory Dijkstra’s Algorithm
10.3
Graph connectivity
Contents
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1 Connectivity
Paths and Circuits
4 Graph Coloring
10.4
Graph connectivity
Paths and Circuits
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
a b c Ngoc Le
Contents
d e f Connectivity
Paths and Circuits
Graph Coloring
d e f
Simple circuit of length 4
10.5
Graph connectivity
Path and Circuits
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition (in undirected graph)
Graph Coloring
d e f d e f
Simple path Not simple path
10.6
Graph connectivity
Path and Circuits
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Graph Coloring
10.7
Graph connectivity
Connectedness in Undirected Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition Ngoc Le
a c h g Others
Graph Coloring
Connected graph
Disconnected graph
Connected components (thành phần liên thông )
10.8
Graph connectivity
How Connected is a Graph?
Huynh Tuong Nguyen,
-A connected graph ‘G’ may have at most (n–2) cut vertices Tran Tuan Anh, Nguyen
Ngoc Le
-a cut edge e G if and only if the edge ‘e’ is not a part of any cycle in G
-the maximum number of cut edges possible is ‘n-1’ (n is num of vertices)
a d f g
Contents
Connectivity
Paths and Circuits
• b is a cut vertex (đỉnh cắt) or articulation point (điểm khớp). Bellman-Ford Algorithm
Floyd-Warshall Algorithm
What else? Ford’s algorithm
Others
• {a, b} is a cut edge (cạnh cắt) or bridge (cầu). What else? Graph Coloring
g
Contents
a e
Connectivity
Paths and Circuits
• The vertex cut is {c, f }, so the minimum number of vertices Floyd-Warshall Algorithm
Ford’s algorithm
in a vertex cut, vertex connectivity (liên thông đỉnh) Others
• The edge cut is {{b, c}, {a, f }, {f, g}}, the minimum number
of edges in an edge cut, edge connectivity (liên thông cạnh)
λ(G) = 3.
10.10
Graph connectivity
Applications of Vertex and Edge Connectivity
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Reliability of networks
Contents
• Minimum number of routers that disconnect the network Connectivity
• Minimum number of fiber optic links that can be down to Paths and Circuits
Graph Coloring
10.11
Graph connectivity
Connectedness in Directed Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition Ngoc Le
c c Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
Others
Graph Coloring
e d e d
u1 v1
Contents
u6 u2 v6 v2 Connectivity
Paths and Circuits
Solution
H has a simple circuit of length three, not G.
10.13
Graph connectivity
Applications
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Determine whether the graphs below are isomorphic.
u2 v2
Contents
Connectivity
u1 u3 v1 v3 Paths and Circuits
Both graphs have the same vertices, edges, degrees, circuits. They Ford’s algorithm
Others
may be isomorphic. Graph Coloring
To find a possible isomorphism, we can follow paths that go
through all vertices so that the corresponding vertices in the two
graphs have the same degrees.
10.14
Graph connectivity
The Famous Problem of Seven Bridges of Königsberg
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Connectivity
Paths and Circuits
• Is there a route that a person crosses all the seven bridges Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Graph Coloring
10.17
Graph connectivity
Euler Solution
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Connectivity
Paths and Circuits
Graph Coloring
10.18
Graph connectivity
What is Euler Path and Circuit?
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph Coloring
10.19
Graph connectivity
Examples of Euler Path and Circuit
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
4 3 D C
Contents
Connectivity
Paths and Circuits
10.20
Graph connectivity
Conditions for Existence
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph Coloring
10.21
Graph connectivity
Back to the Seven Bridges Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Connectivity
Paths and Circuits
Graph Coloring
10.22
Graph connectivity
Searching Euler Circuits and Paths – Fleury’s Algorithm
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph Coloring
10.23
Graph connectivity
Searching Euler Circuits and Paths – Hierholzer’s Algorithm
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
tour but that has adjacent edges not part of the tour, start Euler and Hamilton
Paths
another circuit from v Euler Paths and Circuits
Hamilton Paths and Circuits
Graph Coloring
10.24
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Example Tran Tuan Anh, Nguyen
Ngoc Le
Are these following graph Euler path (circuit)? If yes, find one.
a g f e
Contents
Euler path Connectivity
not Euler circuit Paths and Circuits
f c Graph Coloring
e d 10.25
Graph connectivity
Traveling Salesman Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Connectivity
Paths and Circuits
Graph Coloring
10.26
Graph connectivity
What Is A Hamilton Circuit?
Huynh Tuong Nguyen,
K : n vertices , halminton <=> deg cua moi vertex > n/2 Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The circuit that visit each vertex in a graph once
Contents
Connectivity
Paths and Circuits
Graph Coloring
10.27
Graph connectivity
Rules of Hamilton Circuits
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Connectivity
Paths and Circuits
v
Euler and Hamilton
Paths
Euler Paths and Circuits
Rule 2 No subcircuit (chu trình con) can be formed. Hamilton Paths and Circuits
v Ford’s algorithm
Others
Graph Coloring
10.28
Graph connectivity
Finding Hamilton Circuits
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
a
Vertices : cities
b c
Edges : possible routes Contents
d
Connectivity
Rule 1 Paths and Circuits
deg(v) = 2 Euler and Hamilton
e Paths
Graph Coloring
We get Hamilton circuit!
10.29
Graph connectivity
Existence of Hamilton Circuit
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
condition : NO SUBcircuit
Hamilton circuit does not exist for all graph. But, there is no
specific way to find whether Hamilton circuit exists or not.
Contents
Simple check by rules of Hamilton circuit Connectivity
Paths and Circuits
Graph Coloring
10.30
Graph connectivity
circuit.
a
b c
d Contents
Connectivity
Contradict with Rule 1! Paths and Circuits
i Bellman-Ford Algorithm
Floyd-Warshall Algorithm
j k Ford’s algorithm
Others
Graph Coloring
Hamilton circuit doesn’t exist!
10.31
Graph connectivity
Application – Gray Code
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
The binary sequence that express consecutive numbers by differing
just one position of sequence.
Contents
Connectivity
Decimal number Binary number Gray code Paths and Circuits
.. .. .. Floyd-Warshall Algorithm
Ford’s algorithm
. . . Others
Graph Coloring
Used at digital communication for reduce the effect of noise; it
prevents serious changes of information by noise.
10.32
Graph connectivity
Gray Code
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
5 = 011
7 6 = 111
4
Contents
Connectivity
8 = 001 7 = 101
3 Paths and Circuits
4 = 010
6 3 = 110
5 Euler Paths and Circuits
Hamilton Paths and Circuits
10.33
Graph connectivity
Weighted Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Dien Bien
HA NOI
296 88
Hai Phong
264605
Contents
436
Hamilton Paths and Circuits
Others
6
Graph Coloring
12
HO CHI MINH
230
Can Tho
Con Dao
10.37
Graph connectivity
Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
The problem is also sometimes called the single-pair shortest path problem, to
distinguish it from the following generalizations:
• The single-source shortest path problem, in which we have to find Contents
shortest paths from a source vertex v to all other vertices in the graph. Connectivity
Paths and Circuits
• The single-destination shortest path problem, in which we have to find
Euler and Hamilton
shortest paths from all vertices in the graph to a single destination Paths
vertex v. This can be reduced to the single-source shortest path problem Euler Paths and Circuits
10.38
Graph connectivity
Dijkstra’s Algorithm
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
procedure Dijkstra(G,a)
// Initialization Step
forall vertices v
Label[v] := ∞
Prev[v] := -1
endfor Contents
Label(a) := 0 // a is the source node Connectivity
S := ∅ Paths and Circuits
10.39
Graph connectivity
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
b 5 d
4 6
8
a 1 2 z
Contents
2 3 Connectivity
Paths and Circuits
a 0 4 2 ∞ ∞ ∞ Bellman-Ford Algorithm
Floyd-Warshall Algorithm
c 0 3 2 10 12 ∞ Ford’s algorithm
b 0 3 2 8 12 ∞ Others
Graph Coloring
d 0 3 2 8 10 14
e 0 3 2 8 10 13
10.40
Graph connectivity
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
b 5 d
4 6
8
a 1 2 z
Contents
2 3 Connectivity
Paths and Circuits
a 0 4 22 ∞ ∞ ∞ Bellman-Ford Algorithm
Floyd-Warshall Algorithm
c 0 33 2 10 12 ∞ Ford’s algorithm
b 0 3 2 88 12 ∞ Others
Graph Coloring
d 0 3 2 8 1010 14
e 0 3 2 8 10 1313
10.41
Graph connectivity
Back tracking procedure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
b 5 d
4 6 Contents
8 Connectivity
a 1 2 z Paths and Circuits
∅ 0 ∞ ∞ ∞ ∞ ∞ Ford’s algorithm
Others
a 0 4 2 ∞ ∞ ∞ Graph Coloring
c 0 3 2 10 12 ∞
b 0 3 2 8 12 ∞
d 0 3 2 8 10 14
e 0 3 2 8 10 13
10.42
Graph connectivity
Dijkstra’s Algorithm
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Property Connectivity
Paths and Circuits
Applicable for any G, any length `(vi ) ≥ 0, ∀i; one-to-all; Euler and Hamilton
Paths
complexity O(|V |2 ). Euler Paths and Circuits
Hamilton Paths and Circuits
Graph Coloring
10.43
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Example Ngoc Le
b 2
Contents
e
Connectivity
4 9 Paths and Circuits
8 Ford’s algorithm
1 3 Others
1 2 Graph Coloring
d 2 5
h
f
10.44
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Find the shortest path from e to other vertices using Dijkstra’s
algorithm.
a 4 b 5 c Contents
Connectivity
Paths and Circuits
Graph Coloring
h f 10 g
10.45
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Find the shortest path from e to other vertices using Dijkstra’s
algorithm.
a 4 b 5 c Contents
Connectivity
Paths and Circuits
Graph Coloring
h f 10 g
10.46
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Find the shortest path from a to other vertices using Dijkstra’s
algorithm. Contents
Connectivity
Paths and Circuits
b 5 d Euler and Hamilton
Paths
5 7 Euler Paths and Circuits
Hamilton Paths and Circuits
8
a 3 3 z Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
2 3 Floyd-Warshall Algorithm
Ford’s algorithm
c 10 e Others
Graph Coloring
10.47
Graph connectivity
Dijkstra’s Algorithm Flaw
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph Coloring
c e
10.48
Graph connectivity
Bellman-Ford Algorithm
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
procedure BellmanFord(G,a)
// Initialization Step
forall vertices v
Label[v] := ∞
Prev[v] := -1
Label(a) := 0 // a is the source node
// Iteration Step Contents
for i from 1 to size(vertices)-1 Connectivity
forall vertices v Paths and Circuits
Graph Coloring
Property
any G, any weighted; one-to-all; detect whether there exists a circle of
negative weight; complexity O(|V | × |E|).
10.49
Graph connectivity
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Step a b c d e f
0 0 ∞ ∞ ∞ ∞ ∞
1 0 -2a ∞ ∞ ∞ 3a
2 0 -2 3b ∞ -5b 3 Contents
3 0 -2 3 -4e -5 3 Connectivity
4 0 -2 3 -4 -5 3 Paths and Circuits
-2 -5 Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ford’s algorithm
a 4 3 d Others
Graph Coloring
1 -3
3 1
f 1 e
10.50
Graph connectivity
Backtracking procedure
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Step a b c d e f
0 0 ∞ ∞ ∞ ∞ ∞
1 0 -2a ∞ ∞ ∞ 3a
2 0 -2 3b ∞ -5b 3
3 0 -2 3 -4e -5 3 Contents
Connectivity
4 0 -2 3 -4 -5 3 Paths and Circuits
-2 -5 Floyd-Warshall Algorithm
Ford’s algorithm
Others
a 4 3 d Graph Coloring
1 -3
3 1
f 1 e
10.51
Graph connectivity
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Example Ngoc Le
Step a b c d e f
0 0 ∞ ∞ ∞ ∞ ∞
1 0 -2a ∞ ∞ ∞ ∞
2 0 -2 -1b ∞ -1b ∞
3 0 -2 -1 -6c -1 -4c
Contents
4 -1f -2 -1 -6 -3f -4 Connectivity
5 -1 -3a -1 -6 -3 -4 Paths and Circuits
There exists a circle of negative weight since Step 6 6= Step 5. Shortest Path Problem
Dijkstra’s Algorithm
Bellman-Ford Algorithm
b 1 c Floyd-Warshall Algorithm
Ford’s algorithm
-2 -5 Others
Graph Coloring
a 4 3 d
-3 1
3 1
f 1 e
10.52
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1
Contents
b 1 c Connectivity
Paths and Circuits
f 1 e Floyd-Warshall Algorithm
Ford’s algorithm
Others
Graph Coloring
10.53
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
2
(G1 )
Contents
3
B D Connectivity
Paths and Circuits
4 7 Euler and Hamilton
2 Paths
Euler Paths and Circuits
A 2 3 F Hamilton Paths and Circuits
5 Bellman-Ford Algorithm
C E Floyd-Warshall Algorithm
Ford’s algorithm
12 Others
Graph Coloring
10.54
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1
Contents
b -5 c Connectivity
Paths and Circuits
f 1 e Floyd-Warshall Algorithm
Ford’s algorithm
Others
Graph Coloring
10.55
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
A -2 D 3 E
(G7 )
Contents
4
6 -4 -3 Connectivity
4 Paths and Circuits
Graph Coloring
10.56
Graph connectivity
Floyd-Warshall Algorithm [1962]
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
procedure FloydWarshall ()
for k := 1 to n
Contents
for i := 1 to n
for j := 1 to n Connectivity
Paths and Circuits
path[i,j] = min (path[i,j],
Euler and Hamilton
path[i,k]+path[k,j]); Paths
Euler Paths and Circuits
Hamilton Paths and Circuits
any G, any weighted; all-to-all; this is an software algorithm; complexity Bellman-Ford Algorithm
O(|V |3 ).
Floyd-Warshall Algorithm
Ford’s algorithm
Others
Graph Coloring
10.59
Graph connectivity
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
00 10 ∞0 40
1
20 00 −20 ∞0
L(0) =
30 ∞0 00 ∞0
a
2
b ∞0 −50 −10 00
00 10 ∞0 40
(1)
20 00 − 20 61
3 -5 L =
Contents
30 41 00 71
Connectivity
∞0 − 50 − 10 00 Paths and Circuits
-2 4 00 10 −12 40
Euler and Hamilton
c d 20 00 − 20 61 Paths
-1 L (2) =
30 41 00 71 Euler Paths and Circuits
⇒ bd = bc + ca + ad (4)
13 00 − 20 53 Graph Coloring
L =
30 24 00 71
− 43 − 50 − 72 00
10.60
Graph connectivity
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
2
a 3 b
Contents
1 -4 Connectivity
Paths and Circuits
c
Euler and Hamilton
Paths
00 20 ∞0 00 20 ∞0 Euler Paths and Circuits
10 31 − 12 Ford’s algorithm
Others
Graph Coloring
STOP, there exists a circuit of negative length.
10.61
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
b
7 5 Contents
Connectivity
Graph Coloring
10.62
Graph connectivity
Ford’s algorithm
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
π(1) = 0
Contents
For each j ∈ V do Connectivity
π(j) = mini∈ρ−1 (π(i)+`[i,j]) Paths and Circuits
j
Euler and Hamilton
End Paths
Euler Paths and Circuits
Hamilton Paths and Circuits
G without circle, positive length; one-to-all; rank table definition; complexity Bellman-Ford Algorithm
Floyd-Warshall Algorithm
O(|V |). Ford’s algorithm
Others
Graph Coloring
10.66
Graph connectivity
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
1 1
A B
B
3 4
1 3 4
3
4 0 3 5
Contents
C E 3 5
A C D Connectivity
5 Paths and Circuits
4 2
2 Euler and Hamilton
4 Paths
D Euler Paths and Circuits
i Γ−1
i rank(i) Floyd-Warshall Algorithm
Ford’s algorithm
A - 0 Others
B A 1 Graph Coloring
C A, B 2
D B, C , E 3
E A 1
10.67
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
5 1
A B C
Contents
7 2
Connectivity
Paths and Circuits
3 5
Shortest Path Problem
F 4 Dijkstra’s Algorithm
H Bellman-Ford Algorithm
G 2
Floyd-Warshall Algorithm
Ford’s algorithm
Others
Graph Coloring
10.68
Graph connectivity
Application
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Problem
A young professor in Hue is invited to teach some years in Ho Chi Minh university of
technology. He decides to represent the diverse operations of his transfer by a graph and,
in this purpose, establishes the list of following operations:
A: Find a house in Ho Chi Minh city.
Contents
B: Choose a removal man and sign a contract of move
Connectivity
C: Make pack his furniture by the removal man Paths and Circuits
D: Make transport his furniture towards Ho Chi Minh city Euler and Hamilton
Paths
E: Find an accommodation to HCM (from Hue) Euler Paths and Circuits
F: Transport his family to HCM Hamilton Paths and Circuits
10.69
Graph connectivity
Application
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph Coloring
10.70
Graph connectivity
Question
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Connectivity
How to determine a shortest path from u to v in graph G which Paths and Circuits
Graph Coloring
10.71
Graph connectivity
Other shortest path problems
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Graph Coloring
10.72
Graph connectivity
Traveling Salesman Problem (TSP)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Problem
• Given a set of n customers located in n cities and distances for each pair
of cities, the problem involves finding a round-trip with the minimum Contents
traveling cost. Connectivity
• The vehicle must visit each customer exactly once and return to its point Paths and Circuits
• TSP is one of the most intensely studied problems in computational Floyd-Warshall Algorithm
Ford’s algorithm
mathematics, yet no effective solution method. Others
Graph Coloring
10.74
Graph connectivity
Traveling Salesman Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
b 3 c Ngoc Le
2 2
3 2 4
a d Contents
Connectivity
Paths and Circuits
Graph Coloring
number of solutions is 24!/2 = 3.1 × 1023 .
• If the depot is located at node 1, then the optimal tour is
1 − 5 − 2 − 3 − 4 − 1 with total cost equal to 11.
10.75
Graph connectivity
Vehicle Routing Problem (VRP)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Problem
• The vehicle routing problem involves finding a set of trips,
one for each vehicle, to deliver known quantities of goods to a Contents
Connectivity
set of customers. Paths and Circuits
• The objective is to minimize the travel costs of all trips Euler and Hamilton
Paths
combined. Euler Paths and Circuits
Hamilton Paths and Circuits
• There may be upper bounds on the total load of each vehicle Shortest Path Problem
and the total duration of its trip. Dijkstra’s Algorithm
Bellman-Ford Algorithm
• The most basic Vehicle Routing Problem (VRP) is the Floyd-Warshall Algorithm
Ford’s algorithm
single-depot capacitate VRP. Others
Graph Coloring
10.76
Graph connectivity
Maps and Graphs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• Every map can be represented by a graph. We call it dual
graph.
• Problem of coloring the regions of a map → coloring the Contents
Connectivity
vertices of the dual graph so that no two adjacent vertices Paths and Circuits
A E Floyd-Warshall Algorithm
Ford’s algorithm
C Others
Graph Coloring
10.77
Graph connectivity
Graph coloring
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• A coloring (tô màu) of a simple graph is the assignment of a
color to each vertex of the graph so that no two adjacent
vertices are assigned the same color.
• The chromatic number (số màu) of a graph, denoted by Contents
χ(G), is the least number of colors needed for a coloring of Connectivity
e g e g Graph Coloring
f f
c d c d
10.78
Graph connectivity
Four color theorem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Was not proved completely until 1976 by Kenneth Appel and Euler Paths and Circuits
Hamilton Paths and Circuits
Graph Coloring
10.79
Graph connectivity
Applications of Graph coloring
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Scheduling Final Exam Ngoc Le
6 3 Others
Graph Coloring
5 4
10.80
Graph connectivity
Applications of Graph Coloring
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Other Applications
Connectivity
assigned to stations in North America so that no two stations Paths and Circuits
within 150 miles can operate on the same channel. How can Euler and Hamilton
Paths
the assignment of channels be modeled by graph coloring? Euler Paths and Circuits
• Index Registers: In an execution of loop, the frequently used Hamilton Paths and Circuits
Graph Coloring
10.81
Graph connectivity
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Connectivity
Paths and Circuits
b -5 c Euler and Hamilton
Paths
Euler Paths and Circuits
Hamilton Paths and Circuits
5 1
a d Shortest Path Problem
Dijkstra’s Algorithm
-1 2 Bellman-Ford Algorithm
4 3 Floyd-Warshall Algorithm
Ford’s algorithm
f 1 e Others
Graph Coloring
10.85
Trees
Chapter 11
Ngoc Le
Trees
Discrete Structures for Computing
Contents
Introduction
Properties of Trees
Tree Traversal
Applications of Trees
Binary Search Trees
Decision Trees
Spanning Trees
Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
1 Introduction
Properties of Trees
2 Tree Traversal
Contents
Introduction
Tree Traversal
Binary Search Trees
Applications of Trees
Decision Trees Binary Search Trees
Decision Trees
Spanning Trees
4 Spanning Trees Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
5 Minimum Spanning Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.2
Trees
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
11.3
Trees
Introduction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Introduction
Properties of Trees
/
Tree Traversal
Applications of Trees
Spanning Trees
Minimum Spanning
tan mail ls junk Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.4
Trees
Tree
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A tree (cây ) is a connected undirected graph with no simple circuits.
Consequently, a tree must be a simple graph.
Contents
Introduction
Properties of Trees
Tree Traversal
Applications of Trees
Binary Search Trees
Decision Trees
Spanning Trees
G1 G2 G3 G4
Minimum Spanning
circuit exists Trees
Prim’s Algorithm
Definition
Graphs containing no simple circuits that are not necessarily connected
is forest (rừng ), in which each connected component is a tree.
11.5
Trees
Rooted Trees
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A rooted tree (cây có gốc) is a tree in which:
• One vertex has been designated as the root and
• Every edge is directed away from the root
Contents
Introduction
Properties of Trees
f g a c Tree Traversal
Applications of Trees
Binary Search Trees
d b a Decision Trees
b c Spanning Trees
d e
Minimum Spanning
e b Trees
Prim’s Algorithm
a f g e d Kruskal’s Algorithm
c f g
11.6
Trees
Terminology
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition Ngoc Le
• the ancestors (tổ tiên) of a vertex are the vertices in the path Introduction
Properties of Trees
from the root to this vertex (excluding the vertex itself)
Tree Traversal
• descendants (con cháu) of a vertex v are those vertices that Applications of Trees
Spanning Trees
a Minimum Spanning
Trees
Prim’s Algorithm
b Kruskal’s Algorithm
c
d
f g e
11.7
Trees
Terminology
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• a vertex of a tree is called a leaf (lá ) if it has no children
• vertices that have children are called internal vertices (đỉnh
Contents
trong ) Introduction
Properties of Trees
a Tree Traversal
Applications of Trees
Binary Search Trees
Decision Trees
b
Spanning Trees
c
Minimum Spanning
d Trees
Prim’s Algorithm
Kruskal’s Algorithm
f g e
11.8
Trees
Terminology
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
If a is a vertex in a tree, the subtree (cây con) with a as its root is
the subgraph of the tree consisting of a and its descendants and
all edges incident to these descendants. Contents
Introduction
a Properties of Trees
Tree Traversal
Applications of Trees
b Binary Search Trees
c Decision Trees
d Spanning Trees
Minimum Spanning
Trees
f g e Prim’s Algorithm
Kruskal’s Algorithm
11.9
Trees
m-ary tree
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• m-ary tree (cây m-phân): at most m children on each internal
vertex of a rooted tree. nhieu nhat
• full m-ary tree (cây m-phân đầy đủ): every internal vertex has
exactly m children. tat ca
Contents
• An m-ary tree with m = 2 is called a binary tree (cây nhị phân). Introduction
Properties of Trees
Tree Traversal
Applications of Trees
Binary Search Trees
Decision Trees
Spanning Trees
Full 3-ary tree Minimum Spanning
Trees
Binary tree Prim’s Algorithm
Kruskal’s Algorithm
11.10
Trees
Ordered Rooted Trees
Huynh Tuong Nguyen,
Definition Tran Tuan Anh, Nguyen
Ngoc Le
left child (con bên trái) and the second is called the right Introduction
Properties of Trees
child (con bên phải). Tree Traversal
a Applications of Trees
Binary Search Trees
Decision Trees
b c Spanning Trees
Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
e
f d
g
Left subtree of a Right subtree of a
11.11
Trees
Properties & Theorems
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Theorem
A tree with n vertices has n − 1 edges.
Contents
Theorem Introduction
Tree Traversal
(i) n vertices has (n − 1)/m internal vertices and Applications of Trees
[(m − 1)n + 1]/m leaves Binary Search Trees
Decision Trees
11.12
Trees
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
person, if no one receives more than one letter and if the Binary Search Trees
Decision Trees
chain letter ends after there have been 100 people who read it Spanning Trees
11.13
Trees
Level and Height
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition Ngoc Le
Tree Traversal
a Applications of Trees
Binary Search Trees
b k Spanning Trees
• Level of root a = 0, Minimum Spanning
j b, j, k = 1 and
Trees
Prim’s Algorithm
c f l c, e, f, l = 2 . . . Kruskal’s Algorithm
e
• Because the largest
g level of any vertex is
d i m n
4, this tree has height
4.
h
11.14
Trees
Balanced m-ary Trees
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A rooted m-ary tree of height h is balanced (cân đối) if all leaves
are at levels h or h − 1.
Contents
Introduction
Properties of Trees
Tree Traversal
Applications of Trees
Binary Search Trees
Decision Trees
T1 Spanning Trees
Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
T2
11.15
Trees
Balanced m-ary Tree
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Theorem
There are at most mh leaves in an m-ary tree of height h. Contents
Introduction
Tree Traversal
• If an m-ary tree of height h has ` leaves, then h ≥ dlogm `e. Decision Trees
Spanning Trees
• If the m-ary tree is full and balanced, then h = dlogm `e. Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.16
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
loss and games are played until only one entrant has not lost. Introduction
Tree Traversal
Applications of Trees
Exercise (Isomorphic) Binary Search Trees
Decision Trees
How many different isomers (đồng phân) do the following Spanning Trees
• C5 H12
• C6 H14
11.17
Trees
Question
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
Contents
• How many vertices and how many leaves does a complete Introduction
m-ary tree of height h have? Properties of Trees
Tree Traversal
• Show that a full m-ary balanced tree (cây m-phân hoàn hảo)
Applications of Trees
of height h has more than mh−1 leaves. Binary Search Trees
Decision Trees
• How many edges are there in a forest of t trees containing a
Spanning Trees
total of n vertices? Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.18
Trees
Labeling Ordered Rooted Trees
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
• Ordered rooted trees are often used to store information. Ngoc Le
Introduction
0 Properties of Trees
Tree Traversal
Applications of Trees
Binary Search Trees
1 2 3 Decision Trees
Spanning Trees
Minimum Spanning
1.1 1.2 1.3 3.1 Trees
Prim’s Algorithm
Kruskal’s Algorithm
1.3.1
1.1.1 1.3.2 3.1.1 3.1.2
1.3.1.1
11.19
Trees
Traversal Algorithms (Thuật toán duyệt cây)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Preorder Traversal (duyệt tiền thứ tự - NLR)
procedure preorder (T : ordered rooted tree)
r := root of T
print r
for each child c of r from left to right
Contents
T (c) := subtree with c as its root
Introduction
preorder (T (c)) Properties of Trees
Tree Traversal
a Applications of Trees
Binary Search Trees
Decision Trees
Spanning Trees
b c Minimum Spanning
Trees
d Prim’s Algorithm
Kruskal’s Algorithm
f g e
a b f g c e d
11.20
Trees
Traversal Algorithms
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Introduction
Properties of Trees
a Tree Traversal
Applications of Trees
Binary Search Trees
Decision Trees
b c
Spanning Trees
d
Minimum Spanning
Trees
Prim’s Algorithm
f g e Kruskal’s Algorithm
f b g a e c d
11.21
Trees
Traversal Algorithms
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Postorder Traversal (Duyệt hậu thứ tự - LRN)
procedure postorder (T : ordered rooted tree)
r := root of T
for each child c of r from left to right
T (c) := subtree with c as its root
Contents
postorder (T (c))
Introduction
print r Properties of Trees
Tree Traversal
a Applications of Trees
Binary Search Trees
Decision Trees
Spanning Trees
b c Minimum Spanning
d Trees
Prim’s Algorithm
Kruskal’s Algorithm
f g e
f g b e c d a
11.22
Trees
Infix, Prefix and Postfix Notations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Infix (trung tố ):
((x + y) ↑ 2) + ((x − 4)/3) +
Contents
Introduction
↑ / Properties of Trees
Applications of Trees
+ ↑ +xy2/ − x43 + −
2 3 Binary Search Trees
Decision Trees
Spanning Trees
x y x 4 Minimum Spanning
• Postfix (hậu tố ): Trees
Prim’s Algorithm
x y + 2 ↑ x 4 −3 / + Kruskal’s Algorithm
11.23
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
Implement postorder, inorder and preorder traversal of the
following tree.
Contents
Introduction
A Properties of Trees
Tree Traversal
Applications of Trees
B C Binary Search Trees
Decision Trees
Spanning Trees
D E F Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
G H I
11.24
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
Find the ordered rooted tree representing Contents
Introduction
Tree Traversal
Applications of Trees
Then use this rooted tree to find the prefix, postfix and infix forms Binary Search Trees
Spanning Trees
Minimum Spanning
Solution Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.27
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Exercise
Introduction
Determine postorder of a binary tree with inorder D B H E I A F C Properties of Trees
Applications of Trees
Binary Search Trees
Solution Decision Trees
Spanning Trees
Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.28
Trees
Binary Search Trees
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Binary search tree (cây tìm kiếm nhị phân - BST) is a binary tree
in which the assigned key of a vertex is:
• larger than the keys of all vertices in its left subtree, and
Contents
• smaller than the keys of all vertices in its right subtree. Introduction
Properties of Trees
Tree Traversal
6 Applications of Trees
Binary Search Trees
Decision Trees
2 7 Spanning Trees
Minimum Spanning
Trees
Prim’s Algorithm
1 4 9 Kruskal’s Algorithm
3 5 8
11.32
Trees
Adding and Locating an Item in BST
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Form a BST for the words mathematics, physics, geography ,
zoology , meteorology , geology , psychology , chemistry using
alphabetical order.
Contents
mathematics Introduction
Properties of Trees
Tree Traversal
geography physics Applications of Trees
Binary Search Trees
Decision Trees
Minimum Spanning
Trees
Prim’s Algorithm
psychology Kruskal’s Algorithm
Complexity in searching
O(log(n)) vs. O(n) in linear list
11.33
Trees
Decision Trees (Cây quyết định)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example Contents
Introduction
There are seven coins, all with the same weight, and a counterfeit Properties of Trees
coin that weighs less than the others. How many weighings are Tree Traversal
necessary using a balance scale to determine which of the eight Applications of Trees
coins is the counterfeit one? Give an algorithm for finding this Binary Search Trees
Decision Trees
Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.34
Trees
Yet Another Application
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
If we know that the probability that a person has tuberculosis
(TB) is p(TB) = 0.0005.
We also know p(+|TB) = 0.999 and p(−|TB) = 0.99.
What is p(TB|+) and p(TB|−)? Contents
Introduction
0.999
Properties of Trees
+ TB & + = 0.0004995
Tree Traversal
TB 0.001 Applications of Trees
5
00 − TB & − = 0.0000005 Binary Search Trees
− TB & − = 0.989505
p(TB∩+) 0.0004995
p(TB|+) = p(+) = 0.0004995+0.009995 ≈ 0.0476
11.35
Trees
Problem
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• A spanning tree (cây khung ) in a graph G is a subgraph of G
Contents
that is a tree which contains all vertices of G. Introduction
Properties of Trees
a b c d Tree Traversal
Applications of Trees
Binary Search Trees
Decision Trees
e g Spanning Trees
f Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.36
Trees
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
End! Start!
1
Contents
2 3 4 Introduction
Properties of Trees
Tree Traversal
Stuck! Stuck! Applications of Trees
Spanning Trees
Minimum Spanning
Property Trees
Prim’s Algorithm
11.37
Trees
Depth-First Search
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Algorithm
procedure DFS (G) Contents
Applications of Trees
procedure visit(v: vertex of G) /* recursive */ Binary Search Trees
Decision Trees
for each vertex w adjacent to v and not in T Spanning Trees
add w and edge {v, w} to T Minimum Spanning
visit(w) Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.38
Trees
Breadth-First Search (Tìm kiếm ưu tiên chiều rộng)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
vertex L
Start! ∅
1 1 2, 3, 4
2 3, 4, 5, 6 Contents
3 4, 5, 6 Introduction
4 5, 6, 7, 8 Properties of Trees
2 3 4 5 6, 7, 8 Tree Traversal
Applications of Trees
6 7, 8 Binary Search Trees
8 ∅ Spanning Trees
5 6 7 8 Minimum Spanning
Trees
Prim’s Algorithm
Property Kruskal’s Algorithm
• O(e) or O(n2 )
11.39
Trees
Breadth-First Search
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Algorithm
procedure BFS (G)
T := tree consisting only vertex v1 Contents
11.40
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
Find spanning tree in the following graphs.
a b c
Contents
Introduction
d e f g Properties of Trees
Tree Traversal
Applications of Trees
Binary Search Trees
h i j Decision Trees
Spanning Trees
a b c
Minimum Spanning
Trees
Prim’s Algorithm
Kruskal’s Algorithm
d e f g
h i
11.41
Trees
Minimum Spanning Trees
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
• A minimum spanning tree (cây khung nhỏ nhất) in a
connected weighted graph is a spanning tree that has the
smallest possible sum of weights of its edges.
Contents
Introduction
Properties of Trees
Tree Traversal
$2000 Applications of Trees
Binary Search Trees
Decision Trees
$1200 Chicago $1000 New York Spanning Trees
San Francisco $9
00 00
$13
Minimum Spanning
Trees
Denver
$70
00
Prim’s Algorithm
$1600
$8
Kruskal’s Algorithm
0
$140
0
$220 Atlanta
0
11.42
Trees
Prim’s Algorithm (Nearest-Neighbor)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
11.43
Trees
Prim’s Algorithm (Nearest-Neighbor)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
• Pick a vertex to start from
• Iteratively absorb smallest edge possible
Contents
a 4 b 5 c Introduction
Properties of Trees
Tree Traversal
4 Applications of Trees
1 1 Binary Search Trees
10 Decision Trees
Spanning Trees
d e Minimum Spanning
Trees
Prim’s Algorithm
5 Kruskal’s Algorithm
10
3
f 10 g
11.44
Trees
Kruskal’s Algorithm (Lightest-Edge)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
e := any edge in G with smallest weight that does not form Applications of Trees
Binary Search Trees
a simple circuit when added to T Decision Trees
11.45
Trees
Kruskal’s Algorithm (Lightest-Edge)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
a 4 b 5 c Contents
Introduction
Properties of Trees
4 Tree Traversal
1 1 Applications of Trees
10 Binary Search Trees
Decision Trees
d e Spanning Trees
Minimum Spanning
Trees
5
10 Prim’s Algorithm
3 Kruskal’s Algorithm
f 10 g
11.46
Trees
Exercise
Huynh Tuong Nguyen,
Exercise Tran Tuan Anh, Nguyen
Ngoc Le
a 4 b c
Contents
1 2 5 2 4 1 Introduction
Properties of Trees
d e 2 f g Tree Traversal
1 Applications of Trees
2 3 1 3 1 Binary Search Trees
Decision Trees
h i j Spanning Trees
Minimum Spanning
a 1 b 8 c Trees
Prim’s Algorithm
4 2 4 6 1 2 Kruskal’s Algorithm
d e f g
5 1 3
3 2 7
h i
11.47
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Cho một cây có gốc với n đỉnh. Giả thiết một đỉnh trong tập đỉnh Contents
Tree Traversal
A 1 Applications of Trees
C n Spanning Trees
Minimum Spanning
D 2 Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.48
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Xác định tiền tố (prefix) của cây nhị phân có gốc và có thứ tự
(ordered rooted tree) dùng để biểu diễn Contents
Introduction
Tree Traversal
Applications of Trees
Binary Search Trees
A → ∨¬ ∧ p q ∨ ¬q r ∨ ¬p r Decision Trees
Spanning Trees
B p q ∧ ¬ ∨ q¬r ∧ p¬r∨ →
Minimum Spanning
C p q¬ ∨ q¬ ∧ r → p¬ ∨ r Trees
Prim’s Algorithm
D p q¬ ∨ q¬ ∧ r → p¬ ∨ r Kruskal’s Algorithm
11.49
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Introduction
ABC? Properties of Trees
Tree Traversal
A 1 Applications of Trees
C 5 Spanning Trees
Minimum Spanning
D 7 Trees
Prim’s Algorithm
Kruskal’s Algorithm
11.50
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Hãy cho biết hậu tố (post-order traversal) của một cây nhị phân Contents
biết rằng tiền tố (pre-order traversal) là HBGF DECIA và trung Introduction
tố (in-order traversal) là GBF HCEIDA. Properties of Trees
Tree Traversal
Applications of Trees
A GF BCIEADH Binary Search Trees
Decision Trees
B BGF DECIAH
Spanning Trees
C GF BCIEJADH Minimum Spanning
Trees
D GF BHCIEADH Prim’s Algorithm
Kruskal’s Algorithm
11.51
Trees
Exercise
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Cho đồ thị như trong hình vẽ dưới.
8 14
2 32 12 Contents
24 26 Introduction
Properties of Trees
Tree Traversal
18 28 Applications of Trees
Binary Search Trees
16 30 4 Decision Trees
22 Spanning Trees
Minimum Spanning
Trees
10 20 . Prim’s Algorithm
Kruskal’s Algorithm
Cho trước số tự nhiên a > 1, và xét đồ thị đầy đủ K2a+3 . Số lượng Contents
cạnh ta phải xóa khỏi đồ thị K2a+3 để thu được một cây phủ (cây Introduction
khung hay bao trùm, spanning tree) của K2a+3 là bao nhiêu? Properties of Trees
Tree Traversal
Applications of Trees
A 2a + 2 Binary Search Trees
Spanning Trees
C 4a2 + 3a + 1 Minimum Spanning
Trees
D 2a2 + 3a + 1 Prim’s Algorithm
Kruskal’s Algorithm
11.56
Trees - DFS
Chapter 11
Trees - DFS
Discrete Structures for Computing
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Start!
1
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
Stuck!
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
Stuck!
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
End!
1
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
Property
11.2
Trees - DFS
Depth-First Search
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Algorithm
procedure DFS (G)
T := tree consisting only vertex v1
visit(v1 )
11.3
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B C D
E F G H
11.5
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
11.6
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B C D
E F G H
11.7
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B C D
E F G H
11.8
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
A B C
D E
F
H
G
11.9
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
A B C
D E
F
H
G
11.10
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B D I
C H
E F J K
11.11
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B D I
C H
E F J K
11.12
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
a d f g
b c e h
11.13
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
a d f g
b c e h
11.14
Trees - DFS
Chapter 11
Trees - DFS
Discrete Structures for Computing
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Start!
1
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
Stuck!
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
Stuck!
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
End!
1
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
11.2
Trees - DFS
Depth-First Search (Tìm kiếm ưu tiên chiều sâu)
Huynh Tuong Nguyen,
Nguyen Ngoc Le
2 3 4
5 6 7 8
Property
11.2
Trees - DFS
Depth-First Search
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Algorithm
procedure DFS (G)
T := tree consisting only vertex v1
visit(v1 )
11.3
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
A pseudocode of DFS
Huynh Tuong Nguyen,
Nguyen Ngoc Le
E F G H
11.4
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B C D
E F G H
11.5
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
11.6
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B C D
E F G H
11.7
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B C D
E F G H
11.8
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
A B C
D E
F
H
G
11.9
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
A B C
D E
F
H
G
11.10
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B D I
C H
E F J K
11.11
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
B D I
C H
E F J K
11.12
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
a d f g
b c e h
11.13
Trees - DFS
Exercise
Huynh Tuong Nguyen,
Nguyen Ngoc Le
Exercise
Apply DFS into the following graph.
a d f g
b c e h
11.14