Download presentation

Presentation is loading. Please wait.

Published byAshlynn Dabney Modified over 2 years ago

2
§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. 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

3
§5 Minimum Spanning Tree 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 */ v1v1 v2v2 v6v6 v7v7 v3v3 v4v4 v5v5 2 4 2 1310 7 5 8 4 6 1 2/9

4
§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” ) ; } /* DeleteMin */ /* Union / Find */ A more detailed pseudocode is given by Figure 9.58 on p.321 T = O( |E| log |E| ) Home work: p.341 9.15 A test case and a discussion on uniqueness. 3/9

5
§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 */ 0 123 45 6 DFS ( 0 ) 1. Undirected Graphs void ListComponents ( Graph G ) { for ( each V in G ) if ( !visited[ V ] ) { DFS( V ); printf(“\n“); } 7 8 0 1 4 6 5 2 3 7 8 4/9

6
§6 Applications of Depth-First Search 2. Biconnectivity Articulation point Biconnected graph 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. A biconnected component is a maximal biconnected subgraph. 〖 Example 〗 0 1 23 4 8 7 5 6 9 Connected graph 0 1 1 23 4 35 8 7 7 5 6 7 9 Biconnected components 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

7
§6 Applications of Depth-First Search Finding the biconnected components of a connected undirected G 0 1 23 4 8 7 5 6 9 Use depth first search to obtain a spanning tree of G DFS ( 3 ) 0 1 2 3 4 5 6 7 89 Depth first spanning tree 3 45 2 1 0 6 7 98 0 1 2 3 4 5 6 7 89 Depth first number (Num) 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. Back edges ::= (u, v) tree and u (or v) is an ancestor of v (or u). Note: If u is an ancestor of v, then Num( u ) < Num( v ). 6/9

8
§6 Applications of Depth-First Search 3 45 2 1 0 6 7 98 0 1 2 3 4 5 6 7 89 vertex Num Low 0123456789 4320156798 0054005598 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

9
§6 Applications of Depth-First Search 3. Euler Circuits 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 〖 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

10
§6 Applications of Depth-First Search 2 6 9 8 3 7 1 12 4 10 5 11 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| ) 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| ) Find a simple cycle in an undirected graph that visits every vertex – Hamilton cycle Home work: Self-study the digraphs and strong components on p. 331-334 and do p.342 9.27 DFS 9/9

Similar presentations

OK

C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.

C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on natural resources and wildlife Ppt on 2 stroke ic engine design Ppt on division as equal sharing worksheets Ppt on swami vivekananda free download Ppt on power sharing in india download Ppt on writing effective research questions Ppt on power system stability analysis Ppt on total internal reflection in diamond Ppt on cse related topics in biology Ppt on diode as rectifier circuit