36-SpanTreesKruskPrim

# 36-SpanTreesKruskPrim - Discussion#36 Spanning Trees...

This preview shows pages 1–9. Sign up to view the full content.

Discussion #36 Chapter 7, Section 6 1/17 Discussion #36 Spanning Trees

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Discussion #36 Chapter 7, Section 6 2/17 Topics Spanning trees Minimal spanning trees Kruskal’s algorithm Prim’s algorithm
Discussion #36 Chapter 7, Section 6 3/17 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. S is connected, and 2. S is acyclic. Example: E A D B C F E A D B C F One of many Spanning Trees Why “tree”? Pick any node as the root is a tree. Why “spanning”? Every node is (still) connected to every other node.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Discussion #36 Chapter 7, Section 6 4/17 Algorithm for Generating a Spanning Tree A DFS algorithm works. Just keep the tree edges. E A D B C F O( m ) = O( n 2 ) (worse case) C A D B E F
Discussion #36 Chapter 7, Section 6 5/17 E A D B C F 6 1 4 5 2 Spanning Trees for Weighted Graphs (Only) two minimal spanning trees Weighted Graph E A D B C F 7 6 5 8 1 4 5 2 E A D B C F 6 5 1 4 2 A minimal spanning tree for a weighted , connected, undirected graph G is a graph S consisting of the nodes of G together with enough edges of G such that: 1. S is connected, and 2. S is acyclic, and 3. S has minimal weight . Examples: Note: all weights positive.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Discussion #36 Chapter 7, Section 6 6/17 1 6 5 4 Kruskal’s Algorithm Sort edges by weight (smallest first) For each edge e = { x , y } (in order) if nodes x and y are not in the same connected component, add e E A D B C F 7 6 5 8 1 4 5 2 {A,B} 1 {D,F} 2 {B,C} 4 {A,D} 5 {C,D} 5 {E,D} 6 {A,E} 7 {B,D} 8 2 E C A B D F Could have stopped here… we had n -1 edges.
Discussion #36 Chapter 7, Section 6 7/17 F 2 (4) E 6 (5) D 5 (3) C 4 (2) Prim’s Algorithm Initialize a spanning tree S containing a single vertex, chosen arbitrarily from the graph Until n -1 edges have been added find the edge e = { x , y } such that x is in S and y is not in S e is the smallest weighted edge left Add e and y to S E A D B C F 7 6 5 8 1 4 5 2 B 1 (1) A

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Discussion #36 Chapter 7, Section 6 8/17 Correctness Proofs Correctness Detailed proofs lengthy Essential idea: Prove connected: add edges until all nodes connected
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/02/2012 for the course C S 236 taught by Professor Michaelgoodrich during the Winter '12 term at BYU.

### Page1 / 17

36-SpanTreesKruskPrim - Discussion#36 Spanning Trees...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online