The.Algorithm.Design.Manual.Springer-Verlag.1998
The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998
Connected Components Next: Topological Sorting Up: Graph Problems: Polynomial-Time Previous: Graph Problems: Polynomial-Time Connected Components Input description: A directed or undirected graph G. Problem description: Traverse each edge and vertex of all connected components of G. Discussion: The connected components of a graph represent, in grossest terms, the pieces of the graph. Two vertices are in the same component of G if and only if there is some path between them. Finding connected components is at the heart of many graph applications. For example, consider the problem of identifying clusters in a set of items. We can represent each item by a vertex and add an edge between each pair of items that are deemed ``similar.'' The connected components of this graph correspond to different classes of items. Testing whether a graph is connected is an essential preprocessing step for every graph algorithm. Such tests can be performed so quickly and easily that you should always verify that your input graph is connected, even when you know it has to be. Subtle, difficult-to-detect bugs often result when your algorithm is run only on one component of a disconnected graph. file:///E|/BOOK/BOOK4/NODE159.HTM (1 of 4) [19/1/2003 1:30:54]
Connected Components Testing the connectivity of any undirected graph is a job for either depth-first or breadth-first search, as discussed in Section . Which one you choose doesn't really matter. Both traversals initialize a component-number field for each vertex to 0, and then start the search for component 1 from vertex . As each vertex is visited, the value of this field is set to the current component number. When the initial traversal ends, the component number is incremented, and the search begins again from the first vertex with component-number still 0. Properly implemented using adjacency lists, this runs in O(n+m), or time linear in the number of edges and vertices. Other notions of connectivity also arise in practice: ● What if my graph is directed? - There are two distinct definitions of connected components for directed graphs. A directed graph is weakly connected if it would be connected by ignoring the direction of edges. Thus a weakly connected graph consists of a single piece. A directed graph is strongly connected if there is a directed path between every pair of vertices. This distinction is best made clear by considering a network of one- and two-way streets in a city. The network is strongly connected if it is possible to drive legally between every two positions. The network is weakly connected if it is possible to drive legally or illegally between every two positions. The network is disconnected if there is no possible way to drive from a to b. The weakly and strongly connected components define unique partitions on the vertices. The output figure above illustrates a directed graph consisting of two weakly connected or five strongly connected components (also called blocks of G). Testing whether a directed graph is weakly connected can be done easily in linear time. Simply turn all edges into undirected edges and use the DFS-based connected components algorithm described above. Tests for strong connectivity are somewhat more complicated. The simplest algorithm performs a breadth-first search from each vertex and verifies that all vertices have been visited on each search. Thus in O(mn) time, it can be confirmed whether the graph is strongly connected. Further, this algorithm can be modified to extract all strongly connected components if it is not. In fact, strongly connected components can be found in linear time using one of two more sophisticated DFS-based algorithms. See the references below for details. It is probably easier to start from an existing implementation below than a textbook description. ● How reliable is my network; i.e. how well connected is it? - A chain is only as strong as its weakest link. When it is missing one or more links, it is disconnected. The notion of connectivity of graphs measures the strength of the graph - how many edges or vertices must be removed in order to break it, or disconnect it. Connectivity is an essential invariant for network design and other structural problems. Algorithmic connectivity problems are discussed in Section . In particular, biconnected components are pieces of the graph that result by cutting the edges incident on a single vertex. All file:///E|/BOOK/BOOK4/NODE159.HTM (2 of 4) [19/1/2003 1:30:54]
- Page 415 and 416: Knapsack Problem is a subset of S'
- Page 417 and 418: Discrete Fourier Transform Next: Co
- Page 419 and 420: Discrete Fourier Transform an algor
- Page 421 and 422: Combinatorial Problems Next: Sortin
- Page 423 and 424: Sorting Next: Searching Up: Combina
- Page 425 and 426: Sorting The simplest approach to ex
- Page 427 and 428: Sorting operations, implying an sor
- Page 429 and 430: Searching large performance improve
- Page 431 and 432: Searching Notes: Mehlhorn and Tsaka
- Page 433 and 434: Median and Selection followed by fi
- Page 435 and 436: Generating Permutations Next: Gener
- Page 437 and 438: Generating Permutations The rank/un
- Page 439 and 440: Generating Permutations generating
- Page 441 and 442: Generating Subsets look right when
- Page 443 and 444: Generating Subsets above for detail
- Page 445 and 446: Generating Partitions Although the
- Page 447 and 448: Generating Partitions Two related c
- Page 449 and 450: Generating Graphs generate: ● Do
- Page 451 and 452: Generating Graphs Combinatorica [Sk
- Page 453 and 454: Calendrical Calculations Next: Job
- Page 455 and 456: Calendrical Calculations Gregorian,
- Page 457 and 458: Job Scheduling ● To assign a set
- Page 459 and 460: Job Scheduling shop scheduling incl
- Page 461 and 462: Satisfiability logic, and automatic
- Page 463 and 464: Satisfiability Next: Graph Problems
- Page 465: Graph Problems: Polynomial-Time rec
- Page 469 and 470: Connected Components discussing gra
- Page 471 and 472: Topological Sorting contradiction t
- Page 473 and 474: Minimum Spanning Tree Next: Shortes
- Page 475 and 476: Minimum Spanning Tree help you sort
- Page 477 and 478: Shortest Path Next: Transitive Clos
- Page 479 and 480: Shortest Path easier to program tha
- Page 481 and 482: Shortest Path Related Problems: Net
- Page 483 and 484: Transitive Closure and Reduction
- Page 485 and 486: Transitive Closure and Reduction Al
- Page 487 and 488: Matching augmenting paths and stopp
- Page 489 and 490: Matching Combinatorica [Ski90] prov
- Page 491 and 492: Eulerian Cycle / Chinese Postman ar
- Page 493 and 494: Eulerian Cycle / Chinese Postman Ne
- Page 495 and 496: Edge and Vertex Connectivity Severa
- Page 497 and 498: Edge and Vertex Connectivity Next:
- Page 499 and 500: Network Flow programming model for
- Page 501 and 502: Network Flow Combinatorica [Ski90]
- Page 503 and 504: Drawing Graphs Nicely vertices are
- Page 505 and 506: Drawing Graphs Nicely labs.com/orgs
- Page 507 and 508: Drawing Trees such as the map of th
- Page 509 and 510: Planarity Detection and Embedding N
- Page 511 and 512: Planarity Detection and Embedding p
- Page 513 and 514: Graph Problems: Hard Problems ● C
- Page 515 and 516: Clique approximate even to within a
Connected Components<br />
Next: Topological Sorting Up: Graph Problems: Polynomial-Time Previous: Graph Problems:<br />
Polynomial-Time<br />
Connected Components<br />
Input description: A directed or undirected graph G.<br />
Problem description: Traverse each edge and vertex of all connected components of G.<br />
Discussion: <strong>The</strong> connected components of a graph represent, in grossest terms, the pieces of the graph.<br />
Two vertices are in the same component of G if and only if there is some path between them.<br />
Finding connected components is at the heart of many graph applications. For example, consider the<br />
problem of identifying clusters in a set of items. We can represent each item by a vertex and add an<br />
edge between each pair of items that are deemed ``similar.'' <strong>The</strong> connected components of this graph<br />
correspond to different classes of items.<br />
Testing whether a graph is connected is an essential preprocessing step for every graph algorithm. Such<br />
tests can be performed so quickly and easily that you should always verify that your input graph is<br />
connected, even when you know it has to be. Subtle, difficult-to-detect bugs often result when your<br />
algorithm is run only on one component of a disconnected graph.<br />
file:///E|/BOOK/BOOK4/NODE159.HTM (1 of 4) [19/1/2003 1:30:54]