1.4.1 Connected Components

Problem Input | Problem Output

INPUT                    OUTPUT


Input Description: A directed or undirected graph G. A start vertex s.

Problem: Traverse each edge and vertex of the connected component containing s.

Excerpt from The Algorithm Design Manual: 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.

The best book available for this problem is Leda : A Platform for Combinatorial and Geometric Computing by Kurt Mehlhorn and Stefan Naher.


Implementations

  • LEDA - A Library of Efficient Data Types and Algorithms (C++) (rating 8)
  • Moret and Shapiro's Algorithms P to NP (Pascal) (rating 4)
  • GraphEd -- Graph Editor and Layout Program (C) (rating 4)
  • The Stanford GraphBase (C) (rating 4)
  • Combinatorica (Mathematica) (rating 3)
  • Xtango and Polka Algorithm Animation Systems (C++) (rating 2)
  • Nijenhuis and Wilf: Combinatorial Algorithms (FORTRAN) (rating 2)

    Related Problems

  • Edge and Vertex Connectivity
  • Shortest Path
  • Transitive Closure and Reduction


    Previous Problem Next Problem

    View the graph for this file

    Bulletin Board
    About ``The Algorithm Design Manual''.
    Send us Mail
    The Stony Brook Algorithm Repository -- go to front page

    This page last modified on Wed Mar 07, 2001 .