DM_lect_10-graphs

Download Report

Transcript DM_lect_10-graphs

461191 Discrete Math
Lecture 10: Graphs
San Ratanasanya
CS, KMUTNB
Adapted from Dr. Goanchanart, RSU and Assist. Prof. Suksomboon, LPRU
Today’s topics



Review of Relations
Administrivia
Graphs


9.1 – 9.5
9.6 – 9.8
2
Relations


Relations (ความสัมพันธ ์) แสดงถึงโครงสร ้าง หรือความสัมพันธ ์ของ
่
้
สมาชิกใน set ซึงเราสามารถน
าความสัมพันธ ์นี ไปใช
้แก ้ปัญหาในหลายๆ
่
เรืองได
้ เช่น การออกแบบฐานข ้อมูล การออกแบบและวางเครือข่าย
คอมพิวเตอร ์ เป็ นต ้น
คุณสมบัตท
ิ น่ี่ าสนใจของ Relations เช่น






Reflexive
Symmtric
Antisymmetric
่
Transitiveคาว่า Relation โดยทัวไปจะหมายถึ
/ ง Binary Relation
เราใช ้สัญลักษณ์ a R b แทน relation R จาก a ไป b และ a R b
หมายถึง a และ b ไม่มี relation R ต่อกัน
เราสามารถแสดงใช ้ Matrix หรือ DiGraph ความสัมพันธ ์ได ้
่
3
Examples

Relation บน {1,2,3,4} ใดต่อไปนี้ เป็ น reflexive, symmetric,
antisymmetric, และ transitive ตามลาดับ ?

R1 = { (1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4) }

R2 = { (1,1), (1,2), (2,1) }

R3 = { (1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (4,1), (4,4) }

R4 = { (2,1), (3,1), (3,2), (4,1), (4,2), (4,3) }

R5 = { (1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4) }

R6 = { (3,4) }

Reflexive: R3, R5

Symmetric: R2, R3

Antisymmetric: R4, R5, R6

Transitive: R4, R5, R6
4
Examples

ให ้ A = {1,2,3} และ B = {1,2,3,4} และมี Relation R1 = {(1,1),
(2,2), (3,3)} และ R2 = {(1,1), (1,2), (1,3), (1,4)} จงหา

R1  R2
R1  R2
R1 - R2
R2 – R1

S○R = {(1,0), (1,1), (2,1), (2,2), (3,0), (3,1)}




{(1,1), (1,2), (1,3), (1,4), (2,2), (3,3)}
{(1,1)}
{(2,2), (3,3)}
{(1,2), (1,3), (1,4)}
จงหา Composite ของ R และ S โดยที่ R เป็ น relation จาก {1,2,3}
ไปยัง {1,2,3,4} โดยที่ R = {(1,1), (1,4), (2,3), (3,1), (3,4)} และ S
เป็ น relation จาก {1,2,3,4} ไปยัง {0,1,2} โดยที่ S = {(1,0), (2,0),
(3,1), (3,2), (4,1)}
5
Examples

ให ้ Relation R บน Set แสดงด ้วย Matrix ข ้างล่าง จงหาว่า Rเป็ น
Reflexive, Symmetric และ/หรือ Antisymmetric
R จะเป็ น Reflexive และ Symmetric แต่ไม่เป็ น Antisy
6
Example

่
จงหาว่า Relation ทีแสดงด
้วย Directed Graph ดังรูป
ข ้างล่างเป็ น Reflexive, Symmetric, Antisymmetric
และ/หรือ Transitive
Symmetric
7
Warshall’s Algorithm
8
Equivalence Relations



R ต ้องมีคณ
ุ สมับติ Reflexsive, Symmetric, Transitive
่ จาเป็ นต ้องรู ้
แบ่ง set ออกเป็ นส่วนๆ (Partition) โดยทีไม่
รายละเอียดปลีกย่อยของสมาชิกในส่วนนั้นๆ
ใช ้เป็ นตัวแทน (Representative) คุณสมบัตข
ิ องสมาชิกของ
่ งแล ้วได ้
ส่วนทีแบ่
9
Examples

จงหา Equivalence Class ของ 0 และ 1 สาหร ับ
congruence modulo 4

[0] = {…, -8, -4, 0, 4, 8, …}
10
Partial Ordering



่ คณ
R ทีมี
ุ สมบัต ิ Reflexive, Anti-symmetric, Transitive
POSET = Partially Ordered Set หรือ (S, R) เช่น (Z, >)
หมายถึง ในเซต Z ความสัมพันธ ์ > มีลก
ั ษณะเป็ น Partial
Ordered หรือ > บน Z เป็ น POSET นั่นเอง
POSET สามารถเขียนให ้อยูใ่ นรูปของ Graph ได ้ หรือจะใช ้
11
Hasse diagram ก็ได ้
Examples
12
13
14
15
16
Administrivia

Midterm Exam

Statistic Summary:







n = 109
Max: 15.3
Mean: 6.8
Min: 1
Standard Deviation: 3.00
HW 7 and 8, and Programming Assignment 2 due today
Final Exam (comprehensive) is in 1 month. Be prepared!
17
Graph





กราฟเป็ นโครงสร ้างแบบไม่ตอ
่ เนื่ อง(Discrete Structure) ที่
ประกอบด ้วยส่วนของ Vertices และส่วนของ Edges ที่
่
่
เชือมต่
อระหว่าง Vertices โดยทีเราสามารถแบ่
งกราฟได ้เป็ น
่
หลายชนิ ดตามแต่ลก
ั ษณะการเชือมต่
อของ Edge
่ อมคู
่
Edge 2 edge ใดๆ ทีเชื
ข
่ อง 2 Vertices เดียวกันไม่
สามารถทับกันได ้
ถ ้าเรามี Vertices จานวนนับไม่ถ ้วน (Infinite) เราจะพูดได ้ว่า
เรามี Infinite Graph
ถ ้าเรามี Vertices จานวนจากัด (Finite) เราจะพูดได ้ว่าเรามี
Finite Graph
้
ในบทนี เราจะศึ
กษาเฉพาะ Finite Graph
18
Types of Graph
19
Types of Graph
20
Types of Graph
21
Types of Graph
22
Types of Graph
23
Summary
Type
Edges
Simple graph
Undirected
Multigraph
Undirected
Pseudograph
Undirected
Simple directed graph
Directed
Directed multigraph
Directed
Multiple Edges
Allowed?
Loops Allowed?










24
Exercise




Directed/Undirected?
Multiple Edges?
Loops?
Type?
25
Exercise




Directed/Undirected?
Multiple Edges?
Loops?
Type?
26
Exercise




Directed/Undirected?
Multiple Edges?
Loops?
Type?
27
Exercise




Directed/Undirected?
Multiple Edges?
Loops?
Type?
28
Exercise




Directed/Undirected?
Multiple Edges?
Loops?
Type?
29
Exercise




Directed/Undirected?
Multiple Edges?
Loops?
Type?
30
Exercise




Directed/Undirected?
Multiple Edges?
Loops?
Type?
31
Graph Model
32
Graph Model
33
Graph Model: Influence
34
Graph Model
35
Graph Model
36
Graph Model: Precedence
Graph
37
Graph Terminology
38
Graph Terminology
a
b
c
d
a
f
e
g
e
b
c
d
39
Graph Terminology
40
Graph Terminology
41
Graph Terminology
42
Special Graph
43
Special Graph
44
Special Graph
45
Special Graph
46
Special Graph: Bipartite
47
Special Graph: Bipartite
48
Special Graph: Bipartite
49
Application of Graph: LAN
50
Application of Graph (Parallel
Processing)
51
Construction of New Graph
52
Construction of New Graph
53
Exercise



Number of vertices?
Number of edges?
Degree of each
vertex?
54
Exercise



Number of vertices?
Number of edges?
Degree of each
vertex?
55
Exercise



Number of vertices?
Number of edges?
Degree of each vertex?
56
Exercise



Number of vertices?
Number of edges?
Degree of each
vertex?
57
Exercise







Number of vertices?
Number of edges?
Degree of each vertex?
Initial vertices?
End vertices?
In-degree
Out-degree
58
Exercise







Number of vertices?
Number of edges?
Degree of each vertex?
Initial vertices?
End vertices?
In-degree
Out-degree
59
Graph Representation
60
Graph Representation
61
Graph Representation:Adjacency
Matrix
62
Graph Representation:Adjacency
Matrix
63
Graph Representation:Adjacency
Matrix
64
Graph Representation:Adjacency Matrix
65
Graph Representation:Adjacency
Matrix
8
66
Graph Representation:Incident
Matrix
67
Graph Representation:Incident
Matrix
68
Graph Representation:Incident
Matrix
69
Graph Isomorphism

Greek roots


isos: “equal”
morphe: “form”
70
Graph Isomorphism
71
Graph Isomorphism
72
Graph Isomorphism
73
Graph Isomorphism
74
Graph Isomorphism
75
Graph Isomorphism
76
Graph Isomorphism
77
Graph Isomorphism
78
Graph Isomorphism
79
Connectivity

หลายๆปัญหาสามารถ Model ด ้วยการเดินทาง
ไปตาม Edge ของกราฟ เช่นการส่งข ้อมูลใน
Data Network หรือปัญหาในการวางแผนการ
เดินทางสาหร ับร ้านส่งของ การเก็บขยะ การ
Diagnostic ในระบบเครือข่ายคอมพิวเตอร ์ เป็ น
่ ญหาเหล่านี สามารถแก
้
ต ้น ซึงปั
้ไขได ้โดยการ
Model ด ้วยกราฟ
80
Connectivity:Path
81
Connectivity:Path
82
Connectivity:Path
83
Connectivity:Path
84
Connectivity:Path
85
Connectivity:Path
86
Connectivity:Path
87
Connectivity:Connectness
88
Connectivity:Connectness
89
Path of 2 Vertices
90
Path of 2 Vertices
91
Euler and Hamilton Path

เมือง Konigsberg ประเทศ Prussia ในศตวรรษ
่
ที18
ได ้ถูกแบ่งออกเป็ น 4 ส่วนด ้วยแม่นา้
่
่ อให ้เกิดเกาะกลาง
Pregel ทีไหลผ่
านตัวเมือง ซึงก่
้
ระหว่างแขนงของแม่นาตามรู
ป ดังนั้นชาวเมืองจึง
่ อมส่
่
สร ้างสะพานขึน้ 7 สะพานเพือเชื
วนต่างๆของ
่ นชมเมืองเกิด
่
เดิ
เมืองเข ้าด ้วยกัน นักท่องเทียวที
่
ข ้อสงสัยว่าจะเป็ นไปได ้ไหมทีเขาจะเดิ
นชมทุกส่วน
ของเมืองโดยข ้ามสะพานแต่ละสะพานเพียงครง้ั
เดียว และท ้ายสุดกลับมาทีจุ่ ดเดิม
92
Euler and Hamilton Path
93
Euler and Hamilton Path
94
Euler and Hamilton Path
95
Euler and Hamilton Path
96
Euler and Hamilton Path
97
Euler and Hamilton Path
98
Euler and Hamilton Path
99
Euler and Hamilton Path
100
Euler and Hamilton Path
101
Euler and Hamilton Path
102
Euler and Hamilton Path
103
Euler and Hamilton Path
104
Shortest-Path Problem
105
Ex: Weighted Graph Modeling
an Airline System
106
Ex: Weighted Graph Modeling
an Airline System
107
Ex: Weighted Graph Modeling
an Airline System
108
Shortest-Path Problem
109
Shortest-Path Problem
110
Dijkstra’s Algorithm
111
Dijkstra’s Algorithm
112
Shortest-Path Problem

จงหา Shortest Path ระหว่าง a และ z
113
114
Traveling Salesman Problem
115
Planar Graph

เป็ นไปได ้หรือไม่ทจะ
ี่
่
เชือมต่
อ นา้ ไฟฟ้ า
และ แกส เข ้ากับ
บ ้านทัง้ 3 หลังนี ้
โดยไม่ให ้ท่อส่งทับ
กัน?
116
Planar Graph
Definition 1
117
Examples: Planar Graph?
118
Euler’s Formula
Theorem 1
119
Example
120
Corollary 1
Corollary 2
ถ้า G เป็ นกราฟระนาบธรรมดาทีต
่ อ
่ ถึงกันแล้ว G จะมี vertex ทีม
่ ีดก
ี รีไม่เกิน 5
Corollary 3
121
Examples
122
Kuratowski’s Theorem
Theorem 2
123
Homeomorgraphic Graphs
124
Planar Graph?
125
Graph Coloring


่ ้น จะมีการระบายสีขอบเขตต่างๆ ของแผนที่
ในการทาแผนทีนั
่ าให ้ขอบเขตทีอยู
่ ต
เราจะมีวธิ ก
ี ารอย่างไรทีจะท
่ ด
ิ กันมีสต
ี า่ งกัน
่ ด
และใช ้สีให ้น้อยทีสุ
ปัญหาข ้างต ้นเราสามารถใช ้กราฟแก ้ปัญหาได ้ โดยการสร ้าง
แบบจาลองของแผนที่ โดยให ้จุดแทนขอบเขต และขอบเขตที่
่
อยูต
่ ด
ิ กันให ้มีเส ้นเชือมจุ
ดนั้นๆ
126
127
Graph Coloring
Definition 1
Definition 2
128
Examples
129
Four Color Theorem


้ ดขึนในปี
้
คาถามนี เกิ
1950
พิสจ
ู น์โดย Kenneth Appel และ Wolfgang ในปี 1976
130
Examples
131
Applications of Graph Coloring
132
Applications of Graph Coloring
133
สรุป
134
Homework 9









Section 9.1

11, 12
Section 9.2

36, 37, 47, 48
Section 9.3

34, 44, 60, 61, 64
Section 9.4

38, 39, 49, 54, 55
Section 9.5

24, 25, 56, 64
Section 9.6

4, 21, 23, 27
Section 9.7

4, 5, 8, 13, 19-26, 30
Section 9.8

1, 4, 10, 11, 20, 25
Supplementary

--135
Programming Assignment 3
1.
2.
3.
4.
5.
6.
จงเขียนโปรแกรมเข ้ารหัสแบบ Caesar โดยให ้ผูใ้ ช ้สามารถกาหนด key เองได ้ ในการ
่ น
เข ้ารหัสให ้ใช ้ตัวอักษรภาษาอังกฤษตัวพิมพ ์ใหญ่เท่านั้นและให ้ถือว่าตัวอักขระทีเป็
Space อยู่ตอ
่ จากตัว Z
จงเขียนโปรแกรมเข ้ารหัสแบบ Huffman
จงเขียนโปรแกรม Dijkstra
จงเขียนโปรแกรมจัดตารางสอบ
่ ดเลขแบบ pre-, in-, post-fix
จงเขียนโปรแกรมเครืองคิ
จงเขียนโปรแกรม
วิธก
ี ารส่งงาน:
- ส่งทาง e-mail ใช ้ชือ่ Subject ว่า 461191 Assignm
- ให ้ทาการบีบอัดไฟล ์ต่างๆเป็ นไฟล ์เดียว โดยใช ้ format
่ าการบีบอัดให ้ใช ้ชือไฟล
่
- ไฟล ์ทีท
์เป็ นรหัสนศ.
Each program should be submitted with a report showing
its code and how it works (some screen shorts plus descriptions).
136