上充通大Minimum Spanning Tree(MST) SHANGHAI JLAO TONG UNIVERSITY Spanning tree of a connected graph G:a connected acyclic subgraph of G that includes all of G's vertices Minimum spanning tree of a weighted,connected graph G:a spanning tree of G of the minimum total weight Example: 6 6 C a a a 4 2 2 d 6 d 3 3
Minimum Spanning Tree (MST) Spanning tree of a connected graph G: a connected acyclic subgraph of G that includes all of G’s vertices Minimum spanning tree of a weighted, connected graph G: a spanning tree of G of the minimum total weight Example: c d b a 6 2 4 3 1 c d b a 2 3 1 c d b a 6 4 1
上游充通大粤 Prim's MST algorithm SHANGHAI JLAO TONG UNIVERSITY Start with tree T1 consisting of one (any)vertex and "grow"tree one vertex at a time to produce MST through a series of expanding subtrees T1,T2,...,T On each iteration,construct Ti1 from T;by adding vertex not in T;that is closest to those already in Ti(this is a 'greedy”step!) Stop when all vertices are included
Prim’s MST algorithm Start with tree T1 consisting of one (any) vertex and “grow” tree one vertex at a time to produce MST through a series of expanding subtrees T1 , T2 , …, Tn On each iteration, construct Ti+1 from Ti by adding vertex not in Ti that is closest to those already in Ti (this is a “greedy” step!) Stop when all vertices are included
上游究通大学 Example SHANGHAI JLAO TONG UNIVERSITY 4 4 4 C a 6 6 2 2 2 d d 3 3 b 3 4 4 C a a 1 2 2 3 3
Example c d b a 4 2 6 1 3 c d b a 4 2 6 1 3 c d b a 4 2 6 1 3 c d b a 4 2 6 1 3 c d b a 4 2 6 1 3
上海克通大Notes about Prim's algorithm SHANGHAI JLAO TONG UNIVERSITY Proof by induction that this construction actually yields an MST(CLRS,Ch.23.1).Main property is given in the next page. Needs priority queue for locating closest fringe vertex.The Detailed algorithm can be found in Levitin,P.310. Efficiency O(n2)for weight matrix representation of graph and array implementation of priority queue O(m log n)for adjacency lists representation of graph with n vertices and m edges and min-heap implementation of the priority queue
Notes about Prim’s algorithm Proof by induction that this construction actually yields an MST (CLRS, Ch. 23.1). Main property is given in the next page. Needs priority queue for locating closest fringe vertex. The Detailed algorithm can be found in Levitin, P. 310. Efficiency • O(n 2 ) for weight matrix representation of graph and array implementation of priority queue • O(m log n) for adjacency lists representation of graph with n vertices and m edges and min-heap implementation of the priority queue
The Crucial Property behind Prim's Algorithm SHANGHAI JLAO TONG UNIVERSITY Claim:Let G=(V,E)be a weighted graph and (X,y)be a partition of V (called a cut).Suppose e (x,y)is an edge of E across the cut, where x is in X and y is in Y,and e has the minimum weight among all such crossing edges(called a light edge).Then there is an MST containing e. Y X
The Crucial Property behind Prim’s Algorithm Claim: Let G = (V,E) be a weighted graph and (X,Y) be a partition of V (called a cut). Suppose e = (x,y) is an edge of E across the cut, where x is in X and y is in Y, and e has the minimum weight among all such crossing edges (called a light edge). Then there is an MST containing e. y x X Y