Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees.

Similar presentations


Presentation on theme: "Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees."— Presentation transcript:

1 Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees

2 Unit 5 Graphs & Trees 2 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Because many situations and structures give rise to graphs, graph theory has become an important mathematical tool in a wide variety of subjects, ranging from operations research, computing science and linguistics [ 語言學 ] to chemistry and genetics [ 基因 ]. Recently, there has been considerable interest in tree structures arising in computer science and artificial intelligence. We often organize data in a computer memory store or the flow of information through a system in tree structure form. Indeed, many computer operating systems are designed to be tree structures. Introduction

3 Unit 5 Graphs & Trees 3 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP P Q R S T road map P Q R ST Diagrammatic Representation 5.1 What is a Graph PQ T S R electrical network

4 Unit 5 Graphs & Trees 4 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP An undirected graph G consists of a non-empty set of elements, called vertices [ 頂點 ], and a set of edges [ 邊 ], where each edge is associated with a list of unordered pairs of either one or two vertices called its endpoints. The correspondence from edges to end-points is called an edge-endpoint function. 5.2 Undirected Graph

5 Unit 5 Graphs & Trees 5 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Edge e 1 e 2 e 3 e 4 Endpoints{u, v}{u, w}{v, w}{w, z} u v w z e1e1 e2e2 e3e3 e4e4 vertex-set V(G) = {u, v, w, z} edge-set E(G) = {e 1, e 2, e 3, e 4 } edge-endpoint function Example 5.2-1 (Undirected Graph)

6 Unit 5 Graphs & Trees 6 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP A directed graph G consists of vertices, and a set of edges, where each edge is associated with a list of ordered pair endpoints 5.3 Directed Graph

7 Unit 5 Graphs & Trees 7 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Edge e 1 e 2 e 3 e 4 Endpoints(u, v)(w, u)(w, v)(z, w) vertex-set V(G) = {u, v, w, z} edge-set E(G) = {e 1, e 2, e 3, e 4 } edge-endpoint function u v w z e1e1 e2e2 e3e3 e4e4 Example 5.3-1 (Directed Graph)

8 Unit 5 Graphs & Trees 8 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Two or more edges joining the same pair of vertices are called multiple edges and an edge joining a vertex to itself is called a loop. The degree of a vertex is the number of edges meeting at a given vertex. 5.4 Multiple edges, Loop and Degree

9 Unit 5 Graphs & Trees 9 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP V(G) = {u, v, w, z} E(G) = {e 1, e 2, e 3, e 4, e 5, e 6, e 7 } edge-endpoint function u v w z Multiple edges loop e1e1 e2e2 e3e3 e4e4 e5e5 e6e6 e7e7 deg u = 6, deg v = 5, deg w = 2, deg z = 1 total degree = 6 + 5 + 2 + 1 = 14 Edge e 1 e 2 e 3 e 4 e 5 e 6 e 7 Edge points{u, u}{u, w}{v, w}{v, z}{u, v}{u, v}{u, v} Example 5.4-1 (Multiple edges, Loop and Degree)

10 Unit 5 Graphs & Trees 10 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP A graph G is connected if there is a path in G between any given pair of vertices, and disconnected otherwise. Connected Graph Disconnected Graph components 5.5 Connected and Disconnected Graphs

11 Unit 5 Graphs & Trees 11 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP K2K2 K3K3 K4K4 K5K5 V1V1 V2V2 V1V1 V2V2 V3V3 V1V1 V2V2 V3V3 V4V4 V1V1 V2V2 V3V3 V4V4 V5V5 A complete graph on n vertices, denoted K n, is a simple graph with n vertices v 1, v 2, …… v n whose set of edges contains exactly one edge for each pair of distinct vertices. 5.6 Complete graph

12 Unit 5 Graphs & Trees 12 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP In any graph, the sum of all the vertex-degrees is equal to twice the number of edges.(see e.g.3) No. of edges =7 total degree = 6 + 5 + 2 + 1 = 14 As the consequences of the Handshaking Lemma, the sum of all the vertex-degrees is an even number and the number of vertices of odd degree is even.(e.g. 3 odd deg vertices are:v and z) 5.7 Handshaking Lemma [ 輔助定理 ]

13 Unit 5 Graphs & Trees 13 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP v 1v 2v 3v 4v 1v 2v 3v 4 v 1 v 2 v 3 v 4 A(G) = v1v1 v2v2 v3v3 v4v4 Adjacency [ 毗鄰 ] Matrix A(G) 5.8 Matrix Representations of Undirected Graph

14 Unit 5 Graphs & Trees 14 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Incidence [ 關聯 ] Matrix I(G) v1v1 v2v2 v3v3 v4v4 e1e1 e2e2 e3e3 e4e4 e5e5 e6e6 e7e7 e 1 e 2 e 3 e 4 e 5 e 6 e 7 v 1v 2v 3v 4v 1v 2v 3v 4 I(G) =

15 Unit 5 Graphs & Trees 15 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Adjacency Matrix A(G) v1v1 V2V2 V3V3 e1e1 e2e2 e3e3 e4e4 e5e5 v 1v 2v 3v 1v 2v 3 v 1 v 2 v 3 A(G) = 5.9 Matrix Representations of Directed Graph

16 Unit 5 Graphs & Trees 16 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Incidence Matrix I(G) v1v1 V2V2 V3V3 e1e1 e2e2 e3e3 e4e4 e5e5 v 1v 2v 3v 1v 2v 3 e 1 e 2 e 3 e 4 e 5 I(G) =

17 Unit 5 Graphs & Trees 17 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP A walk of length k between v 1 and v 8 in a graph G is a succession of k edges of G of the form v 1 e 1 v 2, v 2 e 2 v 3, v 3 e 3 v 4, …,v 7 e 7 v 8. We denote this walk by v 1 e 1 v 2 e 2 v 3 e 3 v 4 e 4 v 5 e 5 v 6 e 6 v 7 e 7 v 8. v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 e1e1 e2e2 e3e3 e4e4 e5e5 e6e6 e7e7 v8v8 5.10 Walk

18 Unit 5 Graphs & Trees 18 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP If all the edges (but not necessarily all the vertices) of a walk are different, then the walk is called a path. If, in addition, all the vertices are different, then the trail is called simple path. A closed path is called a circuit. A simple circuit is a circuit that does not have any other repeated vertex except the first and last. 5.11 Paths and circuits

19 Unit 5 Graphs & Trees 19 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP v1v1 v3v3 v5v5 v4v4 v2v2 path v1v1 v3v3 v5v5 v4v4 v2v2 simple path v 1 v 2 v 4 v 1 v 3 v 5 is a pathv 1 v 2 v 4 v 3 v 5 is a simple path Example 5.11-1 (Paths)

20 Unit 5 Graphs & Trees 20 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP v1v1 v3v3 v5v5 v4v4 v2v2 circuit v1v1 v3v3 v5v5 v4v4 v2v2 simple circuit v 1 v 2 v 4 v 3 v 5 v 4 v 1 is a circuitv 1 v 2 v 4 v 5 v 3 v 1 is a simple circuit Example 5.11-2 (Circuits)

21 Unit 5 Graphs & Trees 21 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Repeated EdgeRepeated Vertex Starts and Ends at Same Point Walk Path Simple path Closed walk Circuit Simple circuit Allowed No Allowed No Allowed No Allowed First and last only Allowed No Yes Summarized Table

22 Unit 5 Graphs & Trees 22 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP If G is a graph with vertices v 1, v 2, …… v m and A(G) is the adjacency matrix of G, then for each positive integer n, the ijth entry of A n = the number of walks of length n from v i to v j. 5.12 Counting Walks of Length N

23 Unit 5 Graphs & Trees 23 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP v1v1 v2v2 v3v3 e1e1 e2e2 e3e3 e4e4 Adjacency matrix A(G) Example 5.12-1 (Counting Walks)

24 Unit 5 Graphs & Trees 24 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP one walk of length 2 connecting v 1 to v 1 (v1e1v2e1v1)(v1e1v2e1v1) two walks of length 2 connecting v 1 to v 3 (v 1 e 1 v 2 e 3 v 3, v 1 e 1 v 2 e 4 v 3 ) Example 5.12-1 (cont.)

25 Unit 5 Graphs & Trees 25 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP The objective of this algorithm is to find the shortest path from vertex S to vertex T in a given network. We demonstrate the steps of the algorithm by finding the shortest distance from S to T in the following network: 5.13 The Shortest Path Algorithm

26 Unit 5 Graphs & Trees 26 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP 7 4 9 7 1 3 1 6 3 4 S A T B C D Example 5.13-1 (Shortest Path Alg.)

27 Unit 5 Graphs & Trees 27 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP 7 4 9 7 1 3 1 6 3 4 S A T B C D 0 7 4 9 7 Example 5.13-1(Cont.)

28 Unit 5 Graphs & Trees 28 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP 7 4 9 7 1 3 1 6 3 4 S A T B C D 0 5 4 7 7 Example 5.13-1(Cont.)

29 Unit 5 Graphs & Trees 29 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP 7 4 9 7 1 3 1 6 3 4 S A T B C D 0 5 4 7 7 11 Example 5.13-1(Cont.)

30 Unit 5 Graphs & Trees 30 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP 7 4 9 7 1 3 1 6 3 4 S A T B C D 0 5 4 7 7 10 Example 5.13-1(Cont.)

31 Unit 5 Graphs & Trees 31 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP 7 4 9 7 1 3 1 6 3 4 S A T B C D 0 5 4 7 7 10 Therefore, the shortest path from S to T is SBCT with path length 10 Example 5.13-1(Cont.)

32 Unit 5 Graphs & Trees 32 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Initialization Assign to vertex S potential 0. Label each vertex V reached directly from S with distance from S to V. Choose the smallest of these labels, and make it the potential of the corresponding vertex or vertices. 5.13 The Shortest Path Algorithm Extra Notes

33 Unit 5 Graphs & Trees 33 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP StepVisitedABCDT InitB7S4S9S7SX

34 Unit 5 Graphs & Trees 34 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP StepVisitedABCDT InitB7S4S9S7SX 1A5SB4S7SB7SX

35 Unit 5 Graphs & Trees 35 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP StepVisitedABCDT InitB7S4S9S7SX 1A5SB4S7SB7SX 2D5SB4S7SB7S11SBA

36 Unit 5 Graphs & Trees 36 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP StepVisitedABCDT InitB7S4S9S7SX 1A5SB4S7SB7SX 2D5SB4S7SB7S11SBA 3C5SB4S7SB7S11SBA

37 Unit 5 Graphs & Trees 37 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP StepVisitedABCDT InitB7S4S9S7SX 1A5SB4S7SB7SX 2D5SB4S7SB7S11SBA 3C5SB4S7SB7S11SBA 4T5SB4S7SB7S10SBC

38 Unit 5 Graphs & Trees 38 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP A connected graph G is Eulerian if there is a closed path which includes every edge of G; such a path is called an Eulerian path, and if the path which starts and ends on the same vertex, then it is called Eulerian circuit. 1 2 3 4 5 6 7 8 p q r s t 5.14 Eulerian Graphs

39 Unit 5 Graphs & Trees 39 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Theorem (Eulerian Graph) Let G be a connected graph. Then G has an Eulerian circuit if and only if every vertex of G has even degree,and has an Eulerian path if no more than two vertices have an odd degree. Which of the following graph(s) is/are Eulerian? (a) (b)(c) (d)

40 Unit 5 Graphs & Trees 40 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP The four places (A, B, C and D) in the city of K ö nigsberg were interconnected by seven bridges (p, q, r, s, t, u and v) as shown in the following diagram. Is it possible to find a route crossing each bridge exactly once ? K ö nigsberg A B C D p q r s t u v 5.15 Königsberg bridges problem

41 Unit 5 Graphs & Trees 41 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP By the theorem, it is not a Eulerian graph. It follows that there is no route of the desired kind crossing the seven bridges of K ö nigsberg. We can express the K ö nigsberg bridges problem in terms of a graph by taking the four land areas as vertices and the seven bridges as edges joining the corresponding pairs of vertices. C A B D p r s q t u v Answer (Königsberg bridges problem)

42 Unit 5 Graphs & Trees 42 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP STEP 1Choose a starting vertex u with a vertex of odd degree. STEP 2At each stage, traverse [ 橫越 ] any available edge, choosing a bridge only if there is no alternative. STEP 3After traversing each edge, erase [ 擦掉 ] it (erasing any vertices of degree 0 which result), and then choose another available edge. STEP 4STOP when there are no more edges. 5.16 Fleury’s Algorithm

43 Unit 5 Graphs & Trees 43 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Find the Eulerian path of the following graph. b f ac d e u Example 5.16-1 (Fleury’s Algorithm) Constructing Eulerian paths and circuits

44 Unit 5 Graphs & Trees 44 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Starting at u, we may choose the edge ua, followed by ab. Erasing these edges and the vertex a give us graph (b) b f ac d e u (a) Example 5.16-1 (Cont.)

45 Unit 5 Graphs & Trees 45 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP We cannot use the edge bu since it is a bridge, so we choose the edge bc, followed by cd and db. Erasing these edges and the vertices c and d give us graph (c) b f c d e u (b) Example 5.16-1 (Cont.)

46 Unit 5 Graphs & Trees 46 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP We have to traverse the bridge bu. Traversing the cycle uefu completes the Eulerian path. The path is therefore uabcdbuefu. b f e u (c) Example 5.16-1 (Cont.)

47 Unit 5 Graphs & Trees 47 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP A connected graph G is Hamiltonian if there is a cycle which includes every vertex of G ; such a cycle is called a Hamiltonian cycle. p q rs t p q Hamiltonian Graph rs t Hamiltonian Cycle 5.17 Hamiltonian Graphs

48 Unit 5 Graphs & Trees 48 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Let G be a simple graph with n vertices, where n  3. If deg v  n/2 for each vertex v, then G is Hamiltonian. For the above graph, n = 6 and deg v = 3 for each vertex v, so this graph is Hamitonian by Dirac ’ s theorem. 5.18 DIRAC’S THEOREM

49 Unit 5 Graphs & Trees 49 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Let G be a simple graph with n vertices, where n  3. If deg v + deg w  n, for each pair of non-adjacent vertices v and w, then G is Hamiltonian. 5.19 ORE’S THEOREM

50 Unit 5 Graphs & Trees 50 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP n = 5 but deg u = 2, so Dirac ’ s theorem does not apply. However, deg v + deg w  5 for all pairs of non- adjacent vertices v and w, so this graph is Hamiltonian by Ore ’ s theorem. u Example 5.19-1 (Ore’s Thm)

51 Unit 5 Graphs & Trees 51 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP A tree is a connected graph which contains no cycles. Properties of Tree Every tree with n vertices has exactly n  1 edges. Any two vertices in a tree are connected by exactly one path. Each edge of a tree is a bridge. 5.20 Trees

52 Unit 5 Graphs & Trees 52 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP T is connected and has n  1 edges. T has n  1 edges and contains no cycles. T is connected and each edge is a bridge. Any two vertices of T are connected by exactly one path. 5.21 Alternative definitions of the tree

53 Unit 5 Graphs & Trees 53 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Let G be a connected graph. A spanning tree in G is a subgraph of G that includes all the vertices of G and is also a tree. The edges of the tree are called branches. 5.22 Spanning [ 包括, 延伸 ] Trees

54 Unit 5 Graphs & Trees 54 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP v w x y z vw x y z vw x y z v w x y z A graph G Spanning Trees Example 5.22-1 (Spanning Trees)

55 Unit 5 Graphs & Trees 55 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Let T be a spanning tree of minimum total weight in a connected weighted graph G. Then T is a minimum spanning tree of G. 5.23 Minimum Spanning Tree

56 Unit 5 Graphs & Trees 56 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Illustrated Example A C B D E 2 6 7 5 9 6 4 85 8 5.24 Greedy Algorithm

57 Unit 5 Graphs & Trees 57 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Iteration 1 (Choose an edge of minimum weight) A C B D E 2 6 7 5 9 6 4 85 8 5.24 Greedy Algorithm (cont.)

58 Unit 5 Graphs & Trees 58 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Iteration 2 (Select the vertex from unconnected set {A,B,C} that is closest to connected set {D,E}) A C B D E 2 6 7 5 9 6 4 85 8 5.24 Greedy Algorithm (cont.)

59 Unit 5 Graphs & Trees 59 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Iteration 3 (Select the vertex from unconnected set {A,C} that is closest to connected set {B,D,E,}) A C B D E 2 6 7 5 9 6 4 8 8 5.24 Greedy Algorithm (cont.)

60 Unit 5 Graphs & Trees 60 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Iteration 4 (Select the vertex from unconnected set {C} that is closest to connected set {A,B,D,E}) A C B D E 2 7 5 9 4 8 8 5.24 Greedy Algorithm (cont.)


Download ppt "Unit 5 Graphs & Trees 1 IT Discipline ITD1111 Discrete Mathematics & Statistics STDTLP Unit 5 Discrete Mathematics and Statistics Graphs and Trees."

Similar presentations


Ads by Google