Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Graphs - II CS 2110, Spring Where did I leave that book?
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
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:
Network Layer4-1 Spanning trees r Suppose you have a connected undirected graph m Connected: every node is reachable from every other node m Undirected:
Spanning Trees.
1 7-MST Minimal Spanning Trees Fonts: MTExtra:  (comment) Symbol:  Wingdings: Fonts: MTExtra:  (comment) Symbol:  Wingdings:
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
Parallel Processing and Minimum Spanning Trees Prof. Sin-Min Lee Dept. of Computer Science, San Jose State University.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
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
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.
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.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
WEIGHTED GRAPHS. Weighted Graphs zGraph G = (V,E) such that there are weights/costs associated with each edge Õw((a,b)): cost of edge (a,b) Õrepresentation:
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Week -7-8 Topic - Graph Algorithms CSE – 5311 Prepared by:- Sushruth Puttaswamy Lekhendro Lisham.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Minimum Spanning Trees
Fundamentals, Terminology, Traversal, Algorithms Graph Algorithms Telerik Algo Academy
COSC 2007 Data Structures II Chapter 14 Graphs III.
Spanning Trees Introduction to Spanning Trees AQR MRS. BANKS Original Source: Prof. Roger Crawfis from Ohio State University.
Spanning Trees Introduction to Spanning Trees AQR MRS. BANKS Original Source: Prof. Roger Crawfis from Ohio State University.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Introduction DATA STRUCTURE – Graph electronic circuits networks (roads, flights, communications) CS16 LAX JFK LAX DFW STL HNL FTL.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Prims’ spanning tree algorithm Given: connected graph (V, E) (sets of vertices and edges) V1= {an arbitrary node of V}; E1= {}; //inv: (V1, E1) is a tree,
Minimum Spanning Trees Prof. Sin-Min Lee Dept. of Computer Science, San Jose State University.
Minimum-Cost Spanning Tree CS 110: Data Structures and Algorithms First Semester,
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
Graph Traversal BFS & DFS. Review of tree traversal methods Pre-order traversal In-order traversal Post-order traversal Level traversal a bc d e f g hi.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
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)
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Union-Find  Application in Kruskal’s Algorithm  Optimizing Union and Find Methods.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Trees Dr. Yasir Ali. A graph is called a tree if, and only if, it is circuit-free and connected. A graph is called a forest if, and only if, it is circuit-free.
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
Minimum Spanning Tree Graph Theory Basics - Anil Kishore.
Graph Search Applications, Minimum Spanning Tree
Minimum Spanning Trees
May 12th – Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Spanning Trees.
Minimum Spanning Trees and Shortest Paths
CISC 235: Topic 10 Graph Algorithms.
Short paths and spanning trees
Spanning Trees Longin Jan Latecki Temple University based on slides by
Trees.
Spanning Trees.
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Tree.
Spanning Trees.
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
Spanning Trees Longin Jan Latecki Temple University based on slides by
Minimum spanning trees
Spanning Trees, greedy algorithms
Presentation transcript:

Spanning Trees

2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges do not have an associated direction...then a spanning tree of the graph is a connected subgraph in which there are no cycles A connected, undirected graph Four of the spanning trees of the graph

3 Finding a spanning tree To find a spanning tree of a graph, pick an initial node and call it part of the spanning tree do a search from the initial node: each time you find a node that is not in the spanning tree, add to the spanning tree both the new node and the edge you followed to get to it An undirected graphOne possible result of a BFS starting from top One possible result of a DFS starting from top

4 Minimizing costs Suppose you want to supply a set of houses (say, in a new subdivision) with: electric power water sewage lines telephone lines To keep costs down, you could connect these houses with a spanning tree (of, for example, power lines) However, the houses are not all equal distances apart To reduce costs even further, you could connect the houses with a minimum-cost spanning tree

5 Minimum-cost spanning trees Suppose you have a connected undirected graph with a weight (or cost) associated with each edge The cost of a spanning tree would be the sum of the costs of its edges A minimum-cost spanning tree is a spanning tree that has the lowest cost AB ED FC A connected, undirected graph AB ED FC A minimum-cost spanning tree

6 Kruskal’s algorithm T = empty spanning tree; E = set of edges; N = number of nodes in graph; while T has fewer than N - 1 edges { remove an edge (v, w) of lowest cost from E if adding (v, w) to T would create a cycle then discard (v, w) else add (v, w) to T } Finding an edge of lowest cost can be done just by sorting the edges Efficient testing for a cycle requires a fairly complex algorithm (UNION-FIND) which we don’t cover in this course

7 Prim’s algorithm T = a spanning tree containing a single node s; E = set of edges adjacent to s; while T does not contain all the nodes { remove an edge (v, w) of lowest cost from E if w is already in T then discard edge (v, w) else { add edge (v, w) and node w to T add to E the edges adjacent to w } } An edge of lowest cost can be found with a priority queue Testing for a cycle is automatic Hence, Prim’s algorithm is far simpler to implement than Kruskal’s algorithm

8 Mazes Typically, Every location in a maze is reachable from the starting location There is only one path from start to finish If the cells are “vertices” and the open doors between cells are “edges,” this describes a spanning tree Since there is exactly one path between any pair of cells, any cells can be used as “start” and “finish” This describes a spanning tree

9 Mazes as spanning trees There is exactly one cycle- free path from any node to any other node While not every maze is a spanning tree, most can be represented as such The nodes are “places” within the maze

10 Building a maze I This algorithm requires two sets of cells the set of cells already in the spanning tree, IN the set of cells adjacent to the cells in the spanning tree (but not in it themselves), called the FRONTIER Start with all walls present Pick any cell and put it into IN (red) Put all adjacent cells, that aren’t in IN, into FRONTIER (blue)

11 Building a maze II Repeatedly do the following: Remove any one cell C from FRONTIER and put it in IN Erase the wall between C and some one adjacent cell in IN  Add to FRONTIER all the cells adjacent to C that aren’t in IN (or in FRONTIER already) Continue until there are no more cells in FRONTIER When the maze is complete (or at any time), choose the start and finish cells

12 The End