1 / 17

Minimum Spanning Trees

Minimum Spanning Trees. Definition Algorithms Prim Kruskal Proofs of correctness. Problem Definition. Input Weighted, connected undirected graph G=(V,E) Weight (length) function w on each edge e in E Task Compute a spanning tree of G of minimum total weight Spanning tree

milos
Télécharger la présentation

Minimum Spanning Trees

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Minimum Spanning Trees • Definition • Algorithms • Prim • Kruskal • Proofs of correctness

  2. Problem Definition • Input • Weighted, connected undirected graph G=(V,E) • Weight (length) function w on each edge e in E • Task • Compute a spanning tree of G of minimum total weight • Spanning tree • If there are n nodes in G, a spanning tree consists of n-1 nodes such that no cycles are formed

  3. Kruskal’s algorithm • Greedy approach to edge selection • Select the minimum weight edge that does not form a cycle • Implementation • Sort edges by increasing lengths • Alternatively use heap to store edges • Either way: O(E log E) time • Include minimum weight edge if it does not form a cycle. • How do we test if edge forms a cycle?

  4. 1 4 2 A B C D 5 6 3 10 2 5 E F G Disjoint-set Data Structure • Use disjoint-set data structure (Chapter 21) • Each vertex belongs to a set containing the vertices in its current tree (initially only itself) • Find-set(A) = Find-set(B) = Find-set(E) = A • Find-set(C) = Find-set(D) = C • Find-set(F) = F • Find-set(G) = G

  5. 1 4 2 A B C D 5 6 3 10 2 5 E F G Cycle Detection • Take minimum weight edge and test both endpoints to see if they are in same set • Min weight edge: (A,E). Same Set. Cycle. • Min weight edge: (B,C): Different Sets. No cycle.

  6. Update Disjoint-set Data Structure • Merge sets corresponding to node B and node C. • We need the result to now be: • Find-set(A) = Find-set(B) = Find-set(E) = Find-set(C) = Find-set(D) = A (or C) • Find-set(F) = F • Find-set(G) = G 1 4 2 A B C D 5 6 3 10 2 5 E F G

  7. Time for Disjoint-set Data Structure Operations • Initialization: • Makeset(v) for all vertices v: O(V) time • Merges and Find-set Operations • O(E) of them • Each can be implemented in amortized a(V) time where a is a very slow growing function • O(E a(V)) time overall which is essentially O(E) for all practical purposes

  8. Overall Running Time • Initialization: • Makeset(v) for all vertices v: O(V) time • Merges and Find-set Operations • O(E) of them • Each can be implemented in amortized a(V) time where a is a very slow growing function • O(E a(V)) time overall for cycle detection • O(E log E) time for sorting edges by weight dominates

  9. Prim’s algorithm • Different greedy approach to edge selection • Initialize connected component N to be any node v • Select the minimum weight edge connecting N to V-N • Implementation • Maintain a priority queue for the nodes in V-N based on how close they are to any node in N • When a new node v is added to N, we need to update the weight of the neighbors of v in V-N

  10. 1 4 2 A B C D 5 6 3 10 2 5 E F G Priority Queue • Maintain priority queue of nodes in V-N • If we started with node D, N is now {C,D} • Priority Queue values of other nodes: • A, E, F: infinity • B: 4 • G: 6

  11. 1 4 2 A B C D 5 6 3 10 2 5 E F G Updating Priority Queue • Node B is added to N; edge (B,C) is added to T • Need to update priority queue values of A, E, F • Decrease-key operation • Priority Queue values of other nodes: • A: 1 • E: 2 • F: 5 • G: 6

  12. Updating Priority Queue • Node A is added to N; edge (A,B) is added to T • Need to update priority queue values of E • Decrease-key operation • Priority Queue values of other nodes: • E: 2 (unchanged because 2 is smaller than 3) • F: 5 • G: 6 1 4 2 A B C D 5 6 3 10 2 5 E F G

  13. Running time Analysis • Assume binary heap implementation • Build initial heap takes O(v) time • V extract-min operations for O(V log V) time • For each edge, potentially 1 decrease-key operation, so O(E log V) time • Overall: O(E log V) time which is asymptotically equivalent to our implementation of Kruskal’s algorithm • Use of fibonacci heap can improve running time to O(E + V log V) time • Decrease-key drops to O(1) amortized time

  14. Proofs of Correctness (Kruskal) • Let T’ be a minimum spanning tree for G • Let T be the tree formed by Kruskal’s algorithm that utilizes edges in T’ whenever a tie needs to be broken • Assumption: T has more weight than T’ • Otherwise Kruskal’s algorithm has produced an optimal tree

  15. Proofs of Correctness (Kruskal) • Let e be the smallest weight edge in T that is not in T’ • Add e to T’ and consider the cycle Y that is formed • There must be some edge e’ on Y that has weight greater than e. • Explain why? • What do we know about T and T’ up to this point?

  16. Proofs of Correctness (Kruskal) • Replace e’ by e in T’ • We have a new spanning tree T’’ such that the weight of T’’ is smaller than the weight of T’ • This contradicts the fact that T’ was optimal. • This implies no such edge e can be found, and thus T must be optimal.

  17. Proofs of Correctness (Prim) • Let T’ be a minimum spanning tree for G • Let T be the tree formed by Prim’s algorithm that utilizes edges in T’ whenever a tie needs to be broken • Let e be the first edge added to T that is not in T’ • Finish this argument

More Related