minimum spanning trees. subgraph a graph g is a subgraph of graph h if –the vertices of g are a...
TRANSCRIPT
![Page 1: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/1.jpg)
Minimum Spanning Trees
![Page 2: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/2.jpg)
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.
![Page 3: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/3.jpg)
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.
![Page 4: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/4.jpg)
Spanning Trees
![Page 5: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/5.jpg)
Spanning Trees
a spanning tree
![Page 6: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/6.jpg)
Spanning Trees
another spanning tree(can have many)
![Page 7: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/7.jpg)
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)
![Page 8: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/8.jpg)
Minimum Spanning Trees
4
4 1
3
63 2
17
![Page 9: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/9.jpg)
Minimum Spanning Trees
4
4 1
3
63 2
17
1. Choose any vertex
![Page 10: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/10.jpg)
Minimum Spanning Trees
4
4 1
3
63 2
17
2. Choose minimum weight edge connected to that vertex
![Page 11: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/11.jpg)
Minimum Spanning Trees
4
4 1
3
63 2
17
3. Choose minimum weight edge connected to chosen vertices
![Page 12: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/12.jpg)
Minimum Spanning Trees
4
4 1
3
63 2
17
4. Choose minimum weight edge connected to chosen vertices
![Page 13: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/13.jpg)
Minimum Spanning Trees
4
4 1
3
63 2
17
5. Choose minimum weight edge connected to chosen vertices without creating a cycle
![Page 14: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/14.jpg)
Minimum Spanning Trees
4
4 1
3
63 2
17
6. Choose minimum weight edge connected to chosen vertices without creating a cycle
![Page 15: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/15.jpg)
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”
![Page 16: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/16.jpg)
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.
![Page 17: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/17.jpg)
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’.
![Page 18: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/18.jpg)
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. ✔
![Page 19: Minimum Spanning Trees. 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](https://reader035.vdocument.in/reader035/viewer/2022072009/56649d995503460f94a83da6/html5/thumbnails/19.jpg)
Finis