1 / 16

Minimum Spanning Tree

Minimum Spanning Tree. Sarah Brubaker Tuesday 4/22/8. Minimum Spanning Tree. Input: graph G with weights on the edges Output: connected sub graph G’ of G that includes all the vertices of G, of minimum total weight. Exhaustive Search. List all connected sub-graphs of G

finnea
Download Presentation

Minimum Spanning Tree

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 Tree Sarah Brubaker Tuesday 4/22/8

  2. Minimum Spanning Tree • Input: graph G with weights on the edges • Output: connected sub graph G’ of G that includes all the vertices of G, of minimum total weight

  3. Exhaustive Search • List all connected sub-graphs of G • Return sub-graph with least weight • Number of vertices, N, and number of edges, M • O(mn-1)

  4. Greedy Algorithm • Start with a graph containing just the vertices, G’={V,Ø} • Add edges with the least weight until the graph is connected but no cycles are created • To do this: • Order the edges in increasing weight • While the graph is not connected, add an edge • End when all vertices are connected

  5. Greedy Algorithm - Example Initial Graph: List of Edges:

  6. Greedy Algorithm - Example Start with G’={V,Ø} and sorted list of edges Graph: Sorted List of Edges:

  7. Greedy Algorithm - Example Add edge from list to graph s.t. no cycles are created Remove edge from list Graph: Sorted List of Edges:

  8. Greedy Algorithm - Example Add edge from list to graph s.t. no cycles are created Remove edge from list Graph: Sorted List of Edges:

  9. Greedy Algorithm - Example Add edge from list to graph s.t. no cycles are created Remove edge from list Graph: Sorted List of Edges: • Check for cycles using Depth First Search starting at a vertex in the added edge: • Start at C • C-> D -> F -> C • C gets visited twice => a cycle exists and CF should not be added to the graph

  10. Greedy Algorithm - Example Add edge from list to graph s.t. no cycles are created Remove edge from list End when all vertices can be visited (graph is connected) Graph: Sorted List of Edges: • Check for cycles using Depth First Search starting at a vertex in the added edge: • Start at B • B ->D ->C -> F -> A • If all vertices are visited by DFS, then the graph is connected and we are done

  11. Greedy Algorithm - Example Add edge from list to graph s.t. no cycles are created Remove edge from list End when all vertices can be visited (graph is connected) Graph: Sorted List of Edges: • Check for cycles using Depth First Search starting at a vertex in the added edge: • Start at E • E -> F -> D -> B -> A ->C • All vertices were visited and there were no cycles => we have found a minimum spanning tree with weight 12.

  12. Greedy Algorithm- Psuedocode • Given G = (V, E) • G’ <- (V,Ø) • While G’ is not connected • Add e Є E to G’ s.t. G’ is acyclic and e is minimum • Remove e from E

  13. Greedy Algorithm – Run Time • Initialization – constant • While loop – O(n-1) • Connected graph has n-1 edges • Must add n-1 edges to the graph for it to be connected • Find a minimum e ЄE – O(m) • Make sure G’ is acyclic – O(2n) • DFS is O(m+n)<O(2n) where m<=n-1 • Test connectivity of G’ – O(n) • Can use DFS; could be done in same step as testing acyclicity • Remove e from E - constant • Total Runtime: O(n*(m+2n+n)) ~ O(nm+ n2) -> POLYNOMIAL

  14. Error? • Let X be any subset of the vertices of G, and let edge e be the smallest edge connecting X to G-X. Then e is part of the minimum spanning tree.

  15. Error? • T does not contain e and is a spanning tree • e is smallest edge connecting X = {C,D} to G-X ={A,B,F,E} • Adding e creates a cycle in T • Another spanning tree exists, T2 = T+e-f, where f is another edge that could connect X to G-x • Because e < f, T was not the MST and e must be part of the MST 1 2 4

  16. Error? • In the greedy algorithm, the edge added was always the smallest. • Because the smallest edge to connect two parts of the original graph must be included, each edge added must be a part of the final minimum spanning tree. • In this case, the greedy algorithm is always correct (but we know this is not the case for ALL greedy algorithms).

More Related