Minimum Spanning Tree Neil Tang 4/3/2008 CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Class Overview The minimum spanning tree problem An application Prim’s algorithm Kruskal’s algorithm CS223 Advanced Data Structures and Algorithms
Minimum Spanning Tree Problem The cost of a tree: The sum of the weights of all links on the tree. The Minimum Spanning Tree (MST) problem: Given a weighted undirected graph G, find a minimum cost tree connecting all the vertices on the graph. CS223 Advanced Data Structures and Algorithms
Minimum Spanning Tree Problem CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms An Application Broadcasting problem in computer networks: Find the minimum cost route to send packages from a source node to all the other nodes in the network. CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Prim’s Algorithm Differences between Prim and Dijkstra: Arbitrarily pick a vertex to start with. Relaxation: dw=min(dw, cwv), where v is the newly marked vertex, w is one of its unmarked neighbors, cwv is the weight of edge (w,v) and dw indicates the current distance between w and one of the marked vertices. CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Prim’s Algorithm CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Prim’s Algorithm CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Prim’s Algorithm CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Prim’s Algorithm Trivial: O(|V|2 + |E|) = O(|V|2) Heap: deleteMin |V| times + decreaseKey |E| times O(|V|log|V| + |E|log|V|) = O (|E|log|V|) CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Kruskal’s Algorithm CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Kruskal’s Algorithm O(|E|) O(|E|log|E|) O(|E|log|V|) O(|E|log|V|) Time complexity: O(|E|log|E|) = O (|E|log|V|) CS223 Advanced Data Structures and Algorithms
CS223 Advanced Data Structures and Algorithms Kruskal’s Algorithm CS223 Advanced Data Structures and Algorithms