3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.

Slides:



Advertisements
Similar presentations
Chapter 11 Trees Graphs III (Trees, MSTs) Reading: Epp Chp 11.5, 11.6.
Advertisements

Chapter 5: Tree Constructions
Greedy Algorithms Greed is good. (Some of the time)
10.4 Spanning Trees. Def Def: Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree containing every vertex of G See handout.
Graphs III (Trees, MSTs) (Chp 11.5, 11.6)
Minimum Spanning Tree CSE 331 Section 2 James Daly.
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.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Prim’s Algorithm A Proof. Suppose we have a tree T that is the minimal spanning tree for a graph. Let P be the spanning tree from Prim’s alg. and Then.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Minimal Spanning Trees – Page 1CSCI 1900 – Discrete Structures CSCI 1900 Discrete Structures Minimal Spanning Trees Reading: Kolman, Section 7.5.
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
Applied Combinatorics, 4th Ed. Alan Tucker
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
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:
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
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.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
3/29/05Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 4.2 Minimal Spanning Trees Prepared by Amanda Dargie and Michele Fretta.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
2/10/03Tucker, Sec Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
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.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 2 Graph Algorithms.
Foundations of Discrete Mathematics
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
1 Section 1.4 Graphs and Trees A graph is set of objects called vertices or nodes where some pairs of objects may be connected by edges. (A directed graph.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
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,
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
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.
Lectures on Greedy Algorithms and Dynamic Programming
Introduction to Graph Theory
Chap 8 Trees Def 1: A tree is a connected,undirected, graph with no simple circuits. Ex1. Theorem1: An undirected graph is a tree if and only if there.
15-853Page :Algorithms in the Real World Planar Separators I & II – Definitions – Separators of Trees – Planar Separator Theorem.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
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,
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Chapter 11. Chapter Summary Introduction to Trees Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum Spanning.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Applied Discrete Mathematics Week 15: Trees
Minimum Spanning Tree Chapter 13.6.
Discrete Mathematicsq
12. Graphs and Trees 2 Summary
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Applied Combinatorics, 4th Ed. Alan Tucker
Spanning Trees Longin Jan Latecki Temple University based on slides by
Applied Combinatorics, 4th Ed. Alan Tucker
Spanning Trees.
Spanning Trees.
Chapter 23 Minimum Spanning Tree
And the Final Subject is…
Minimum Spanning Tree.
Spanning Trees Longin Jan Latecki Temple University based on slides by
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter

2 3.3 Spanning Trees A spanning tree of a graph G is a subgraph of G that is a tree containing all vertices of G. Spanning trees can be constructed either by depth first (backtrack) search or by breadth-first search.

3 Adjacency Matrix: An adjacency matrix of an (undirected) graph is a (0,1)-matrix with a 1 in entry if the vertex, and vertex are adjacent; entry is 0 otherwise. These are sometimes used to test if a graph is connected x1x1 x2x2 x3x3 x8x8 x7x7 x6x6 x4x4 x5x5 Graph G Adjacency Matrix of G

4 Building a Depth-First spanning tree: To check if G is connected. Pick some vertex as the root and begin building a path from the root composed of edges of the graph. The path continues until it cannot go any further without repeating a vertex already on the path. The vertex where this path must stop is a leaf. We now backtrack to the parent of this leaf and try to build a path from the parent in another direction, and so on, as in the depth-first search method in a later slide.

5 Building a Breadth-First Spanning Tree To check if G is connected. ●Pick some vertex x as the root and put all the edges leaving x (along with the vertices at the ends of these edges) in the tree. ● Then we successively add to the tree the edges leaving the vertices adjacent from x, unless such an edge goes to a vertex already in the tree. ● We continue this process as in the breadth-first search method described on the next slide.

6 Minimal Spanning Trees G is a graph with weights on the edges. A minimal spanning tree, a spanning tree whose sum of the edge weights is as small as possible C B E F A D

7 3.3 Spanning Tree Kruskal’s Algorithm Add to T the shortest edge that does not form a circuit with edges already in T. Repeat this step until tree T has n-1 edges (initially T is empty). (n = # vertices) Prim’s Algoritm Add to T the shortest edge between a vertex in T and a vertex not in T (initially pick any edge of shortest length). Repeat this step until tree T had n-1 edges (n = # vertices)

8 3.3 Spanning Tree Example 2 Kruskal’s Algorithm Step 1: Include all edges of length 1 (in red) Step 2: Add all edges of length 2 (in blue) Step 3: Add almost all the edges of length 3 (in green) except for (w,x) because it would form a circuit. Step 4: We would add all edges of length 4 (purple) and either (m,n) or (o,t) to obtain a minimal spanning tree produced by Prim’s algorithm. Root at b, splits at l, s, m, and h. f g h i j a b c d e k l m n o p q r s t u v w x y

9 3.3 Spanning Tree Example 2 Prim’s Algorithm Step 1: Pick an edge with shortest length, in this example we’ll use (a,f ). Step 2: Add the next edge of shortest length (2): (a, b ). Continuing adding the edge with the next smallest length. f g h i j a b c d e k l m n o p q r s t u v w x y

3.3 Spanning Tree Theorem Prim’s algorithm yields a minimal spanning tree. Proof: For simplicity, assume that the edges all have different lengths. Let T’ be a minimal spanning tree chosen to have as many edges as possible in common with the tree T* constructed by Prim’s algorithm.

Spanning Tree Proof (continued) If T* ≠ T’, let = (a,b) be the first edge chosen by Prim’s algorithm that is not in T’. This means that the subtree, composed of the first k-1 edges composed by Prim’s algorithm, is part of the minimal tree T’. In figure 1, edges of are in bold, ‘s edge is dashed, and the other edges of T’ are drawn normally. Since is not in the minimal spanning tree T’, there is a path, call it P, in T’ that connects a to b. At least one of the edges of P must not be in, for otherwise P would form a circuit in the tree formed by the first k edges in Prim’s algorithm. Let be the first edge along P (starting from a) that is not in. Note that one end of vertex of is in. a b

Spanning Tree Proof (continued) If is shorter than, then on the kth iteration, Prim’s algorithm would have incorporated not. If is greater than, we remove from T’ and replace it with. The new T’ is still a spanning tree, but its length is shorter—this contradicts the minimality of the original T’. ◊ a b

Spanning Tree Class Work Exercise 1c, Pg. 114 For the following graph, construct the adjacency matrix and then find a depth-first spanning tree. a b c d e f g h

Spanning Tree Class Work Exercise 1c, Pg. 114 The depth-first spanning tree is: a-b-c-d-e-f-g-h. a b c d e f g h ABCDEFGH A B C D E F G H

Spanning Tree Class Work Exercise 1c, Pg. 114 For the following graph, now find a minimal spanning tree, using both Kruskal’s and Prim’s algorithms. a b c d e f g h

16 a b c d e f g h a b c d e f g h Kruskal’s Minimal Spanning Tree: Prim’s Minimal Spanning Tree: Now all the vertices are in the tree. Weight = 19 Now all the vertices are included in this tree. Weight = 19