Download presentation
Presentation is loading. Please wait.
Published byAlannah Carr Modified over 9 years ago
1
Minimum Spanning Trees
2
Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a subset of the edges of H.
3
Spanning Tree A spanning tree of a graph G is a subgraph of G that is a tree and includes all the vertices of G. Every connected graph has a spanning tree –Start with G. If G is a tree then it is a ST of G. If not, G has a cycle. Remove any edge of the cycle. The result is a connected subgraph of G. Repeat. Process must terminate since the number of edges is finite.
4
Spanning Trees
5
a spanning tree
6
Spanning Trees another spanning tree (can have many)
7
Weighted Graphs A weighted graph is a graph with a mapping of edges to R + assigning a weight to each edge A minimum spanning tree of a weighted graph is a spanning tree of minimum total weight (sum of the weights of the edges in the tree)
8
Minimum Spanning Trees 4 4 1 3 6 3 2 1 7
9
4 4 1 3 6 3 2 1 7 1. Choose any vertex
10
Minimum Spanning Trees 4 4 1 3 6 3 2 1 7 2. Choose minimum weight edge connected to that vertex
11
Minimum Spanning Trees 4 4 1 3 6 3 2 1 7 3. Choose minimum weight edge connected to chosen vertices
12
Minimum Spanning Trees 4 4 1 3 6 3 2 1 7 4. Choose minimum weight edge connected to chosen vertices
13
Minimum Spanning Trees 4 4 1 3 6 3 2 1 7 5. Choose minimum weight edge connected to chosen vertices without creating a cycle
14
Minimum Spanning Trees 4 4 1 3 6 3 2 1 7 6. Choose minimum weight edge connected to chosen vertices without creating a cycle
15
Prim’s algorithm To find a MST of a connected weighted graph G, we build a tree one edge at a time –Start with T being any node of G –Pick a minimum weight edge that does not create a cycle and that connects a node in T to a node not in T. Add that edge to T. –Repeat until all nodes of G have been added to T. A “Greedy algorithm”
16
Proof that Prim’s algorithm works Invariant: At every stage, T is a subgraph of a MST True initially since T is just a single node The algorithm runs until all nodes have been added to T, so in the end the invariant says that T is a MST. So we just need to show that each stage of the algorithm preserves the invariant.
17
Proof that the algorithm maintains the invariant Proof by contradiction. Suppose there is a stage at which the invariant is true before and false after. Let e be the edge added when the invariant is first violated. Suppose e joins node v in T to node w not in T. So T is a subgraph of a MST but T+e is not. Let T’ be a MST of which T is a subgraph. Edge e is not in T’.
18
Proof that the algorithm maintains the invariant Since T’ is a spanning tree, there is a path p from v to w in T’. Path p does not go through e since e is not part of T’. So p+e is a cycle consisting of two different paths from u to v. Path p must include an edge f which has one end in T and the other not in T. Edge f must have weight ≥ the weight of e, otherwise the algorithm would have chosen to add edge f to T instead of e. Removing f from T’ and adding e results in a spanning tree of weight ≤ the weight of T’ and including T as a subgraph, contradicting the assumption that T+e was not a subgraph of a MST. ✔
19
Finis
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.