Presentation is loading. Please wait.

Presentation is loading. Please wait.

Minimum-Cost Spanning Tree and Kruskal’s Algorithm

Similar presentations


Presentation on theme: "Minimum-Cost Spanning Tree and Kruskal’s Algorithm"— Presentation transcript:

1 Minimum-Cost Spanning Tree and Kruskal’s Algorithm
CS 105

2 Minimum-cost spanning tree
Given a weighted graph G, determine a spanning tree with minimum total edge cost Recall: spanning subgraph means all vertices are included, tree means the graph is connected and has no cycles Useful in applications that ensure connectivity of nodes at optimal cost Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 2

3 Kruskal’s algorithm Solves the minimum-cost spanning tree problem
Strategy: repeatedly select the lowest-cost edge as long as it does not form a cycle with previously selected edges Stop when n-1 edges have been selected (recall n is the number of vertices) Use a priority queue of edges to facilitate selection of lowest-edge cost (just discard edges that form a cycle) Time complexity: O( m log m ) => O( m log n ) Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 3

4 Kruskal’s algorithm BOS ORD PVD JFK SFO BWI DFW LAX MIA 2704 867 849
187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 4

5 Kruskal’s algorithm BOS ORD PVD PVD JFK JFK SFO BWI DFW LAX MIA 2704
867 ORD 849 PVD PVD 187 1846 144 740 621 802 JFK JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 5

6 Kruskal’s algorithm BOS ORD PVD JFK SFO BWI BWI DFW LAX MIA 2704 867
849 PVD 187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI BWI 1090 DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 6

7 Kruskal’s algorithm BOS BOS ORD PVD JFK SFO BWI DFW LAX MIA 2704 867
849 PVD 187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 7

8 Kruskal’s algorithm BOS ORD PVD JFK SFO SFO BWI DFW LAX LAX MIA 2704
867 ORD 849 PVD 187 1846 144 740 621 802 JFK SFO SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 8

9 Kruskal’s algorithm BOS ORD ORD PVD JFK SFO BWI DFW LAX MIA 2704 867
849 PVD 187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 9

10 Kruskal’s algorithm BOS ORD PVD JFK SFO BWI DFW LAX MIA 2704 867 849
187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 10

11 Kruskal’s algorithm BOS ORD PVD JFK SFO BWI DFW DFW LAX MIA 2704 867
849 PVD 187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 11

12 Kruskal’s algorithm BOS ORD PVD JFK SFO BWI DFW LAX MIA MIA 2704 867
849 PVD 187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 946 1121 MIA MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 12

13 Kruskal’s algorithm BOS ORD PVD JFK SFO BWI DFW LAX MIA 2704 867 849
187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 13

14 Kruskal’s algorithm BOS ORD PVD JFK SFO BWI DFW LAX MIA 2704 867 849
187 1846 144 740 621 802 JFK SFO 1464 184 1258 1391 337 BWI 1090 DFW 1235 LAX 946 1121 MIA 2342 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Graphs Slide 14


Download ppt "Minimum-Cost Spanning Tree and Kruskal’s Algorithm"

Similar presentations


Ads by Google