SlideServe
Menu
Préférences
© SlideServe · v2026

Minimum Spanning Tree

finnea avatar
16 diapositives · 389 Views · Oct 15, 2014

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

Minimum Spanning Tree - slide 1
01 / 16Minimum Spanning Tree
1 / 17

Télécharger la présentation

Minimum Spanning Tree
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  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).