Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture19: Graph III Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)

Similar presentations


Presentation on theme: "Lecture19: Graph III Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)"— Presentation transcript:

1 Lecture19: Graph III Bohyung Han CSE, POSTECH bhhan@postech.ac.kr CSED233: Data Structures (2014F)

2 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Spanning Tree Definition and property  Subgraph that contains all vertices of the original graph and is a tree  Often, a graph has many different spanning trees.  Cost of spanning tree: the sum of the edge weights in the spanning tree: 10 + 8 + 13 + 15 + 11 = 57  Useful in constructing networks: a minimum spanning tree gives the way to connect a set of points with the smallest total amount of wire 2 CB A E D F 10 8 Graph 13 3 7 15 11 9 21 CB A E D F 10 8 Spanning tree 13 15 11

3 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Minimum Spanning Tree (MSP) A spanning tree with the minimum cost  Cost: 3 + 8 + 7 + 9 + 11 = 28 Finding the minimum spanning tree  Prim’s algorithm  Kruskal’s algorithms 3 CB A E D F 10 8 Graph 13 3 7 15 11 9 21 CB A E D F 8 Minimum spanning tree 3 7 11 9

4 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Prim’s Algorithm 4

5 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Prim’s Algorithm 5

6 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example Find a minimum spanning tree of the following weighted graph using Prim’s algorithm. 6 C B A D E F 3 4 7 1 6 6 9 8 2

7 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example Starting from A 7 C B A D E F 3 4 7 1 6 6 9 8 2 VertexBCDEF Priority12inf Edge(A,B)(A,C)---

8 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example Add the first priority vertex, B. 8 C B A D E F 3 4 7 1 6 6 9 8 2 VertexCDEF Priority2inf1 Edge(A,C)-(B,E)-

9 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example 9 C B A D E F 3 4 7 1 6 6 9 8 2 VertexCDF Priority1inf2 Edge(A,C)-(E,F)

10 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example 10 C B A D E F 3 4 7 1 6 6 9 8 2 VertexDF Priority21 Edge(C,D)(E,F)

11 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example 11 C B A D E F 3 4 7 1 6 6 9 8 2 VertexD Priority1 Edge(C,D)

12 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example 12 C B A D E F 3 4 7 1 6 6 9 8 2

13 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Kruskal’s Algorithm 13

14 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example Find a minimum spanning tree of the following weighted graph using Kruskal’s algorithm. 14 C B A D E F 3 4 7 1 6 6 9 8 2 Edge(A,B)(A,C)(B,C)(B,E)(C,E)(C,D)(C,F)(E,F)(D,F) Priority347158952

15 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example Start with the edge with minimum weight. 15 C B A D E F 3 4 7 1 6 6 9 8 2 Edge(A,B)(A,C)(B,C)(C,E)(C,D)(C,F)(E,F)(D,F) Priority23647841

16 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example Add the first priority edge as long as it does not create a cycle. 16 C B A D E F 3 4 7 1 6 6 9 8 2 Edge(A,B)(A,C)(B,C)(C,E)(C,D)(C,F)(E,F) Priority1253673

17 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example 17 C B A D E F 3 4 7 1 6 6 9 8 2 Edge(A,C)(B,C)(C,E)(C,D)(C,F)(E,F) Priority142562

18 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example 18 C B A D E F 3 4 7 1 6 6 9 8 2 Edge(B,C)(C,E)(C,D)(C,F)(E,F) Priorityinf 231

19 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 An Example 19 C B A D E F 3 4 7 1 6 6 9 8 2 Edge(B,C)(C,E)(C,D)(C,F) Priorityinf

20 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Analysis of MST Algorithms 20

21 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Hamiltonian Cycle A cycle that goes through every vertex exactly once 21 C B A D E F C B A D E F

22 CSED233: Data Structures by Prof. Bohyung Han, Fall 2014 Traveling Salesperson Problem (TSP) 22

23 23


Download ppt "Lecture19: Graph III Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)"

Similar presentations


Ads by Google