1 / 9

§5 Minimum Spanning Tree

§5 Minimum Spanning Tree. 【Definition】 A spanning tree of a graph G is a tree which consists of V( G ) and a subset of E( G ). 〖 Example 〗 A complete graph and three of its spanning trees. Note:

ura
Download Presentation

§5 Minimum Spanning Tree

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. §5 Minimum Spanning Tree 【Definition】 A spanning tree of a graph G is a tree which consists of V( G ) and a subset of E( G ) 〖Example〗 A complete graph and three of its spanning trees • Note: • The minimum spanning tree is a tree since it is acyclic -- the number of edges is |V| – 1. • It is minimum for the total cost of edges is minimized. • It is spanning because it covers every vertex. • A minimum spanning tree exists iff G is connected. • Adding a non-tree edge to a spanning tree, we obtain a cycle. 1/9

  2. §5 Minimum Spanning Tree 2 v1 v2 4 1 3 10 7 2 v3 v4 v5 4 8 5 6 1 v6 v7 Greedy Method Make the best decision for each stage, under the following constrains : (1) we must use only edges within the graph; (2) we must use exactly |V| 1 edges; (3) we may not use edges that would produce a cycle. 1. Prim’s Algorithm – grow a tree /* very similar to Dijkstra’s algorithm */ 2/9

  3. §5 Minimum Spanning Tree 2. Kruskal’s Algorithm – maintain a forest void Kruskal ( Graph G ) { T = { } ; while ( T contains less than |V| 1 edges && E is not empty ) { choose a least cost edge (v, w) from E ; delete (v, w) from E ; if ( (v, w) does not create a cycle in T ) add (v, w) to T ; else discard (v, w) ; } if ( T contains fewer than |V| 1 edges ) Error ( “No spanning tree” ) ; } T = O( |E| log |E| ) Home work: p.341 9.15 A test case and a discussion on uniqueness. /* DeleteMin */ /* Union / Find */ A more detailed pseudocode is given by Figure 9.58 on p.321 3/9

  4. 0 1 2 3 4 5 6 7 8 §6 Applications of Depth-First Search /* a generalization of preorder traversal */ void DFS ( Vertex V ) /* this is only a template */ { visited[ V ] = true; /* mark this vertex to avoid cycles */ for ( each W adjacent to V ) if ( !visited[ W ] ) DFS( W ); } /* T = O( |E| + |V| ) as long as adjacency lists are used */ 1. Undirected Graphs DFS ( 0 ) void ListComponents ( Graph G ) { for ( each V in G ) if ( !visited[ V ] ) { DFS( V ); printf(“\n“); } } 0 1 4 6 5 2 3 7 8 4/9

  5. §6 Applications of Depth-First Search   0 8 9 0 8 1 7  1 1 7 7 9 2 3 5 2 3 3 5 5  7  4 6 4 6 Connected graph Biconnected components 2. Biconnectivity v is an articulation point if G’ = DeleteVertex( G, v ) has at least 2 connected components.  G is a biconnected graph if G is connected and has no articulation points. Biconnected graph Articulation point  A biconnected component is a maximal biconnected subgraph. 〖Example〗 Note: No edges can be shared by two or more biconnected components. Hence E(G) is partitioned by the biconnected components of G. 5/9

  6. §6 Applications of Depth-First Search 0 Back edges ::= (u, v)  tree and u (or v) is an ancestor of v (or u). 0 8 9 3 1 5 1 7 4 5 2 6 2 3 5 2 6 3 7 4 6 1 7 4 8 9 0 9 8 Finding the biconnected components of a connected undirected G  Use depth first search to obtain a spanning tree of G Depth first spanning tree DFS ( 3 ) Depth first number (Num) 9 8 4 Note: If u is an ancestor of v, then Num( u ) < Num( v ). 3 7 2 0 5 1 6  Find the articulation points in G  The root is an articulation point iff it has at least 2 children  Any other vertex u is an articulation point iff u has at least 1 child, and it is impossible to move down at least 1 step and then jump up to u’s ancestor. 6/9

  7. §6 Applications of Depth-First Search vertex 0 1 2 3 4 5 6 7 8 9 0 Num 4 3 2 0 1 5 6 7 9 8 Low 3 1 5 4 5 2 6 2 6 3 7 1 7 4 8 9 0 9 8 4 0 0 0 0 5 5 5 9 8 Therefore, u is an articulation point iff (1) u is the root and has at least 2 children; or (2) u is not the root, and has at least 1 child such that Low( child )  Num( u ). Please read the pseudocodes on p.327 and p.329 for more details. 7/9

  8. §6 Applications of Depth-First Search Draw each line exactly once without lifting your pen from the paper – Euler tour Draw each line exactly once without lifting your pen from the paper, AND finish at the starting point – Euler curcuit 3. Euler Circuits 〖Proposition〗An Euler circuit is possible only if the graph is connected and each vertex has an even degree. 〖Proposition〗An Euler tour is possible if there are exactly two vertices having odd degree. One must start at one of the odd-degree vertices. 8/9

  9. §6 Applications of Depth-First Search 1 2 3 4 5 6 7 8 9 10 11 12 Find a simple cycle in an undirected graph that visits every vertex – Hamilton cycle DFS Home work: Self-study the digraphs and strong components on p. 331-334 and do p.342 9.27 • Note: • The path should be maintained as a linked list. • For each adjacency list, maintain a pointer to the last edge scanned. • T = O( |E| + |V| ) 9/9

More Related