Spanning Trees.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Networks Prim’s Algorithm
Minimum Spanning Tree Sarah Brubaker Tuesday 4/22/8.
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
Chen, Lu Mentor: Zhou, Jian Shanghai University, School of Management Chen213.shu.edu.cn.
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
1 Section 9.4 Spanning Trees. 2 Let G be a simple graph. A spanning subtree of G is a subgraph of G containing every vertex of G –must be connected; contains.
MINIMAL CONNECTOR PROBLEMS Problem: A cable TV company is installing a system of cables to connect all the towns in a region. The numbers in the network.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
1 Spanning Trees Lecture 20 CS2110 – Spring
Discussion #36 Spanning Trees
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
3/29/05Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 4.2 Minimal Spanning Trees Prepared by Amanda Dargie and Michele Fretta.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
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.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Minimum Spanning Tree in Graph - Week Problem: Laying Telephone Wire Central office.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley. All rights reserved.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Greedy methods Prudence Wong
Copyright © Cengage Learning. All rights reserved.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Minimum Spanning Trees Prof. Sin-Min Lee Dept. of Computer Science, San Jose State University.
Minimum Spanning Trees Suppose G = (V, E) is a undirected network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …) Determine.
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
Spanning Trees. A spanning tree for a connected, undirected graph G is a graph S consisting of the nodes of G together with enough edges of G such that:
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
© 2010 Pearson Prentice Hall. All rights reserved. CHAPTER 15 Graph Theory.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
Graph Search Applications, Minimum Spanning Tree
COMP108 Algorithmic Foundations Greedy methods
May 12th – Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees
Discrete Mathematicsq
Spanning Trees.
Graph Algorithm.
Minimum-Cost Spanning Tree
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Minimum Spanning Tree.
CSE 373 Data Structures and Algorithms
Spanning Trees.
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Networks Kruskal’s Algorithm
Minimum Spanning Tree.
Minimum Spanning Trees
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
CSE 373: Data Structures and Algorithms
Networks Prim’s Algorithm
Graphs.
Algorithms CSCI 235, Spring 2019 Lecture 35 Graphs IV
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
CSE 373: Data Structures and Algorithms
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Topological Sorting Minimum Spanning Trees Shortest Path
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Spanning Trees

Graph - Spanning Tree A tree that contains every vertex of a connected graph is called spanning tree. It is an undirected tree consisting of only those edges that are necessary to connect all the vertices of the original graph G. CHARACTERISTICS  It is a subgraph of a graph G that contain all the vertex of graph G. For any pair of vertices, there exists only one path between them. It is a connected graph with no cycles. A graph may have many spanning tree.

EXAMPLE

Graph - Minimum Spanning Tree Let G=(V,E,W) be any weighted graph. Then a spanning tree whose cost is minimum is called minimum spanning tree. The cost of the spanning tree is defined as the sum of the costs of the edges in that tree.

Kruskal's algorithm It is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted graph. It finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. If the graph is not connected, then it finds a minimum spanning forest (a minimum spanning tree for each connected component). Kruskal's algorithm is an example of a greedy algorithm.

Kruskal's algorithm Create a forest F (a set of trees), where each vertex in the graph is a separate tree Create a set S containing all the edges in the graph Repeat Step 4 and 5, while S is nonempty and F is not yet spanning Remove an edge with minimum weight from S IF that edge connects two different trees, then add it to the forest, combining two trees into a single tree ELSE discard that edge. Exit At the termination of the algorithm, the forest has only one component and forms a minimum spanning tree of the graph.

Example of Kruskal’s Algorithm This is our original graph. The numbers near the arcs indicate their weight. None of the arcs are highlighted.

AD and CE are the shortest arcs, with length 5, and AD has been arbitrarily chosen, so it is highlighted. CE is now the shortest arc that does not form a cycle, with length 5, so it is highlighted as the second arc.

The next arc, DF with length 6, is highlighted using much the same method. The next-shortest arcs are AB and BE, both with length 7. AB is chosen arbitrarily, and is highlighted. The arc BD has been highlighted in red, because there already exists a path (in green) between B andD, so it would form a cycle (ABD) if it were chosen.

The process continues to highlight the next-smallest arc, BE with length 7. Many more arcs are highlighted in red at this stage: BC because it would form the loop BCE, DE because it would form the loop DEBA, and FE because it would form FEBAD. Finally, the process finishes with the arc EG of length 9, and the minimum spanning tree is found.

Prim's algorithm It is a greedy algorithm that finds a minimum spanning tree for a connected weighted undirected graph. Same as in Kruskal’s Algorithm, it finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the tree is minimized. It is also sometimes called the DJP algorithm, the Jarnik algorithm, or the Prim–Jarnik algorithm.

Prim's algorithm (contd..) The only spanning tree of the empty graph (with an empty vertex set) is again the empty graph. The following description assumes that this special case is handled separately. The algorithm continuously increases the size of a tree, one edge at a time, starting with a tree consisting of a single vertex, until it spans all vertices.

Input: A non-empty connected weighted graph with vertices V and edges E (the weights can be negative). Algorithm: Initialize: Vnew = {x}, where x is an arbitrary node (starting point) from V, Enew = { } Repeat Step 3 and 4, until Vnew = V Choose an edge (u, v) with minimal weight such that u is in Vnew and v is not (if there are multiple edges with the same weight, any of them may be picked) Add v to Vnew, and (u, v) to Enew Exit Output: Vnew and Enew describe a minimal spanning tree

Example of Prim’s Algorithm This is our original weighted graph. The numbers near the edges indicate their weight.

Vertex D has been arbitrarily chosen as a starting point Vertex D has been arbitrarily chosen as a starting point. Vertices A, B, E and F are connected to D through a single edge. A is the vertex nearest to D and will be chosen as the second vertex along with the edge AD. The next vertex chosen is the vertex nearest to either D or A. B is 9 away from D and 7 away from A, E is 15, and F is 6. F is the smallest distance away, so we highlight the vertex F and the arc DF.

The algorithm carries on as above The algorithm carries on as above. Vertex B, which is 7 away from A, is highlighted. In this case, we can choose between C, E, and G. C is 8 away from B, E is 7 away from B, and G is 11 away from F. E is nearest, so we highlight the vertex E and the arc BE.

Here, the only vertices available are C and G Here, the only vertices available are C and G. C is 5 away from E, and G is 9 away from E. C is chosen, so it is highlighted along with the arc EC. Vertex G is the only remaining vertex. It is 11 away from F, and 9 away from E. E is nearer, so we highlight it and the arc EG.

Now all the vertices have been selected and the minimum spanning tree is shown in green. In this case, it has weight 39.

{A,B,D,E,F} (B,C) = 8 (D,B) = 9 cycle (D,E) = 15 cycle (E,C) = 5 V (E,G) = 9 (F,E) = 8 cycle (F,G) = 11 {C,G} {A,B,C,D,E,F} (B,C) = 8 cycle (D,B) = 9 cycle (D,E) = 15 cycle (E,G) = 9 V (F,E) = 8 cycle (F,G) = 11 {G} {A,B,C,D,E,F,G} (B,C) = 8 cycle (D,B) = 9 cycle (D,E) = 15 cycle (F,E) = 8 cycle (F,G) = 11 cycle { } U Edge(u,v) V - U { } {A,B,C,D,E,F,G} {D} (D,A) = 5 V (D,B) = 9 (D,E) = 15 (D,F) = 6 {A,B,C,E,F,G} {A,D} (D,F) =6 V (A,B) = 7 {B,C,E,F,G} {A,D,F} (A,B) = 7 V (F,E) = 8 (F,G) = 11 {B,C,E,G} {A,B,D,F} (B,C) = 8 (B,E) = 7 V (D,B) = 9 cycle {C,E,G}