Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 38 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
38
Dung lượng
538,5 KB
Nội dung
COMP 2210 Course Notes Slide 1 Auburn University Computer Science and Software Engineering Course Notes Set: Graphs 2 COMP 2210 Dr. Hendrix Computer Science and Software Engineering Auburn University COMP 2210 Course Notes Slide 2 Auburn University Computer Science and Software Engineering Acknowledgements Portions of these notes were adapted from those developed by Carrano and Savitch and Sartaj Sahni to accompany their texts. COMP 2210 Course Notes Slide 3 Auburn University Computer Science and Software Engineering Tree • Connected graph that has no cycles. • n vertex connected graph with n-1 edges. COMP 2210 Course Notes Slide 4 Auburn University Computer Science and Software Engineering Spanning Tree • Subgraph that includes all vertices of the original graph. • Subgraph is a tree. – If original graph has n vertices, the spanning tree has n vertices and n-1 edges. COMP 2210 Course Notes Slide 5 Auburn University Computer Science and Software Engineering A Spanning Tree Spanning tree cost = 46. 2 3 8 10 1 4 5 9 11 6 7 4 8 6 6 7 5 2 4 4 5 3 8 2 COMP 2210 Course Notes Slide 6 Auburn University Computer Science and Software Engineering Spanning Tree • Start a breadth-first search at any vertex of the graph. • If graph is connected, the n-1 edges used to get to unvisited vertices define a spanning tree. • Time – O(n^2) when adjacency matrix used – O(n+e) when adjacency lists used (e is number of edges) COMP 2210 Course Notes Slide 7 Auburn University Computer Science and Software Engineering Spanning Tree Breadth-first search from vertex 1. 2 3 8 1 4 5 9 6 7 1 2 4 3 6 5 9 7 8 Breadth-first spanning tree. COMP 2210 Course Notes Slide 8 Auburn University Computer Science and Software Engineering Minimum-Cost Spanning Tree • weighted connected undirected graph • cost of spanning tree is sum of edge costs • find spanning tree that has minimum cost COMP 2210 Course Notes Slide 9 Auburn University Computer Science and Software Engineering Minimum Cost Spanning Tree • Tree cost is sum of edge weights/costs. 2 3 8 10 1 4 5 9 11 6 7 4 8 6 6 7 5 2 4 4 5 3 8 2 COMP 2210 Course Notes Slide 10 Auburn University Computer Science and Software Engineering Minimum Cost Spanning Tree Spanning tree cost = 41. 2 3 8 10 1 4 5 9 11 6 7 4 8 6 6 7 5 2 4 4 5 3 8 2