Discrete Mathematics for Computer Science คณิตศาสตร์ไม่...

77
Graph กราฟเป็นโครงสร้างแบบไม่ต่อเนื่อง(Discrete Structure) ที่ประกอบด้วยส่วนของ Vertices และส่วนของ Edges ที่เชื่อมต่อระหว่าง Vertices โดยที่เราสามารถแบ่ง กราฟได้เป็นหลายชนิดตามแต่ลักษณะการเชื่อมต่อของ Edge Edge 2 edge ใดๆ ที่เชื่อมคู่ของ 2 Vertices เดียวกันไม่สามารถทับกันได้ ถ้าเรามี Vertices จานวนนับไม่ถ้วน (Infinite) เราจะพูดได้ว่าเรามี Infinite Graph ถ้าเรามี Vertices จานวนจากัด (Finite) เราจะพูดได้ว่าเรามี Finite Graph ในบทนี้เราจะศึกษาเฉพาะ Finite Graph 1

Transcript of Discrete Mathematics for Computer Science คณิตศาสตร์ไม่...

Page 1: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph

• กราฟเปนโครงสรางแบบไมตอเนอง(Discrete Structure) ทประกอบดวยสวนของ Vertices และสวนของ Edges ทเชอมตอระหวาง Vertices โดยทเราสามารถแบงกราฟไดเปนหลายชนดตามแตลกษณะการเชอมตอของ Edge

• Edge 2 edge ใดๆ ทเชอมคของ 2 Vertices เดยวกนไมสามารถทบกนได• ถาเราม Vertices จ านวนนบไมถวน (Infinite) เราจะพดไดวาเราม Infinite Graph• ถาเราม Vertices จ านวนจ ากด (Finite) เราจะพดไดวาเราม Finite Graph• ในบทนเราจะศกษาเฉพาะ Finite Graph

1

Page 2: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Types of Graph

2

Page 3: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Types of Graph

3

Page 4: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Types of Graph

4

Page 5: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Types of Graph

5

Page 6: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Types of Graph

6

Page 7: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Summary

7

DirectedDirected multigraph

DirectedSimple directed graph

UndirectedPseudograph

UndirectedMultigraph

UndirectedSimple graph

Loops Allowed?Multiple Edges Allowed?

EdgesType

Page 8: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

• Directed/Undirected?

• Multiple Edges?

• Loops?

• Type?

8

Page 9: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

9

Directed/Undirected?

Multiple Edges?

Loops?

Type?

Page 10: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

10

Directed/Undirected?

Multiple Edges?

Loops?

Type?

Page 11: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

11

Directed/Undirected?

Multiple Edges?

Loops?

Type?

Page 12: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

12

Directed/Undirected?

Multiple Edges?

Loops?

Type?

Page 13: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

13

Directed/Undirected?

Multiple Edges?

Loops?

Type?

Page 14: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

14

Directed/Undirected?

Multiple Edges?

Loops?

Type?

Page 15: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Model

15

Page 16: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Model

16

Page 17: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Model: Influence

17

Page 18: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Terminology

18

a

b c d

ef g

a b c

de

Page 19: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Special Graph

19

Page 20: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Special Graph

20

Page 21: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Special Graph

21

Page 22: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Special Graph: Bipartite

22

Page 23: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Special Graph: Bipartite

23

Page 24: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Special Graph: Bipartite

24

Page 25: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Application of Graph: LAN

25

Page 26: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Construction of New Graph

26

Page 27: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

• Number of vertices?

• Number of edges?

• Degree of each vertex?

27

Page 28: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

28

Number of vertices?

Number of edges?

Degree of each vertex?

Page 29: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

29

Number of vertices?

Number of edges?

Degree of each vertex?

Page 30: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Exercise

30

Number of vertices?

Number of edges?

Degree of each vertex?

Page 31: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation

31

Page 32: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation

32

Page 33: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation:Adjacency Matrix

33

Page 34: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation:Adjacency Matrix

34

Page 35: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation:Adjacency Matrix

35

Page 36: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation:Adjacency Matrix

36

Page 37: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation:Adjacency Matrix

37

Page 38: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation:Incident Matrix

38

Page 39: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation:Incident Matrix

39

Page 40: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Representation:Incident Matrix

40

Page 41: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Isomorphism

• Greek rootsisos: “equal”

morphe: “form”

41

Page 42: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Isomorphism

42

Page 43: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Isomorphism

43

Page 44: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Isomorphism

44

Page 45: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Isomorphism

45

Page 46: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Isomorphism

46

Page 47: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Isomorphism

47

Page 48: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Graph Isomorphism

48

Page 49: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Connectivity

• หลายๆปญหาสามารถ Model ดวยการเดนทางไปตาม Edge ของกราฟ เชนการสงขอมลใน Data Network หรอปญหาในการวางแผนการเดนทางส าหรบรานสงของ การเกบขยะ การ Diagnostic ในระบบเครอขายคอมพวเตอร เปนตน ซงปญหาเหลานสามารถแกไขไดโดยการ Model ดวยกราฟ

49

Page 50: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Connectivity:Path

50

Page 51: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Connectivity:Path

51

Page 52: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Connectivity:Path

52

Page 53: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Connectivity:Path

53

Page 54: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Path of 2 Vertices

54

Page 55: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

• เมอง Konigsberg ประเทศ Prussia ในศตวรรษท18 ไดถกแบงออกเปน 4 สวนดวยแมน า Pregel ทไหลผานตวเมอง ซงกอใหเกดเกาะกลางระหวางแขนงของแมน าตามรป ดงนนชาวเมองจงสรางสะพานขน 7 สะพานเพอเชอมสวนตางๆของเมองเขาดวยกน นกทองเทยวทเดนชมเมองเกดขอสงสยวาจะเปนไปไดไหมทเขาจะเดนชมทกสวนของเมองโดยขามสะพานแตละสะพานเพยงครงเดยว และทายสดกลบมาทจดเดม

55

Page 56: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

56

Page 57: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

57

Page 58: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

58

Page 59: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

59

Page 60: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

60

Page 61: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

61

Page 62: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

62

Page 63: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

63

Page 64: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

64

Page 65: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

65

Page 66: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

66

Page 67: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Euler and Hamilton Path

67

Page 68: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Shortest-Path Problem

68

Page 69: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Ex: Weighted Graph Modeling an Airline System

69

Page 70: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Ex: Weighted Graph Modeling an Airline System

70

Page 71: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Ex: Weighted Graph Modeling an Airline System

71

Page 72: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Shortest-Path Problem

72

Page 73: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Shortest-Path Problem

73

Page 74: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Dijkstra’s Algorithm

74

Page 75: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Dijkstra’s Algorithm

75

Page 76: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

Shortest-Path Problem

• จงหา Shortest Path ระหวาง a และ z

76

Page 77: Discrete Mathematics for Computer Science คณิตศาสตร์ไม่ ...mathcom.uru.ac.th/~beebrain/Slide/4122303A/Graph_Data.pdf · Euler and Hamilton Path •เมือง

77

a (0,a) x x x x x

b (4,a) (4,a) (4,a) x x x

c - - (7,c) (7,c) (7,c) x

d (2,a) (2,a) x x x x

e - (5,d) (5,d) (5,d) x x

z - - - (6,e) (6,e) x