Download presentation

Presentation is loading. Please wait.

Published byFrank Weaver Modified over 5 years ago

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

2
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
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. 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 1 0 x1x1 x2x2 x3x3 x8x8 x7x7 x6x6 x4x4 x5x5 Graph G Adjacency Matrix of G

4
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
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
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. 4 3 9 1 10 2 7 5 6 2 C B E F A D

7
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
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 4 6 2 5 a b c d e 2 8 4 3 k l m n o 3 2 5 4 p q r s t 5 7 3 4 u v w x y 7 3 3 2 1 7 3 2 5 2 1 3 3 4 10 1 7 8 8 2 2 9 5 6

9
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 4 6 2 5 a b c d e 2 8 4 3 k l m n o 3 2 5 4 p q r s t 5 7 3 4 u v w x y 7 3 3 2 1 7 3 2 5 2 1 3 3 4 10 1 7 8 8 2 2 9 5 6

10
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.

11
11 3.3 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

12
12 3.3 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

13
13 3.3 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 5 3 5 4 6 8 3 2 2 2 4 3 1 1

14
14 3.3 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 5 3 5 4 6 8 3 2 2 2 4 3 1 1 ABCDEFGH A01101011 B10100000 C11011010 D00101000 E10110110 F00001010 G10101101 H10000010

15
15 3.3 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 5 3 5 4 6 8 3 2 2 2 4 3 1 1

16
16 a b c d e f g h 5 3 5 4 6 8 3 2 2 2 4 3 1 1 a b c d e f g h 5 3 5 4 6 8 3 2 2 2 4 3 1 1 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

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google