
Ingraph theory, acomponent of anundirected graph is aconnectedsubgraph that is not part of any larger connected subgraph. The components of any graphpartition its vertices intodisjoint sets, and are theinduced subgraphs of those sets. A graph that is itself connected has exactly one component, consisting of the whole graph. Components are sometimes calledconnected components.
The number of components in a given graph is an importantgraph invariant, and is closely related to invariants ofmatroids,topological spaces, andmatrices. Inrandom graphs, a frequently occurring phenomenon is the incidence of agiant component, one component that is significantly larger than the others; and of apercolation threshold, an edge probability above which a giant component exists and below which it does not.
The components of a graph can be constructed inlinear time, and a special case of the problem,connected-component labeling, is a basic technique inimage analysis.Dynamic connectivity algorithms maintain components as edges are inserted or deleted in a graph, in low time per change. Incomputational complexity theory, connected components have been used to study algorithms with limitedspace complexity, andsublinear time algorithms can accurately estimate the number of components.

A component of a given undirected graph may be defined as a connected subgraph that is not part of any larger connected subgraph. For instance, the graph shown in the first illustration has three components. Every vertex of a graph belongs to one of the graph's components, which may be found as theinduced subgraph of the set of verticesreachable from.[1] Every graph is thedisjoint union of its components.[2] Additional examples include the following special cases:
Another definition of components involves the equivalence classes of anequivalence relation defined on the graph's vertices.In an undirected graph, avertex isreachable from avertex if there is apath fromto, or equivalently awalk (a path allowing repeated vertices and edges).Reachability is an equivalence relation, since:
Theequivalence classes of this relation partition the vertices of the graph intodisjoint sets, subsets of vertices that are all reachable from each other, with no additional reachable pairs outside of any of these subsets. Each vertex belongs to exactly one equivalence class. The components are then theinduced subgraphs formed by each of these equivalence classes.[7] Alternatively, some sources define components as the sets of vertices rather than as the subgraphs they induce.[8]
Similar definitions involving equivalence classes have been used to defined components for other forms of graphconnectivity, including theweak components[9] andstrongly connected components ofdirected graphs[10] and thebiconnected components of undirected graphs.[11]
The number of components of a given finite graph can be used to count the number of edges in itsspanning forests: In a graph with vertices and components, every spanning forest will have exactly edges. This number is thematroid-theoreticrank of the graph, and therank of itsgraphic matroid. The rank of thedual cographic matroid equals thecircuit rank of the graph, the minimum number of edges that must be removed from the graph to break all its cycles. In a graph with edges, vertices and components, the circuit rank is.[12]
A graph can be interpreted as atopological space in multiple ways, for instance by placing its vertices as points ingeneral position in three-dimensionalEuclidean space and representing its edges as line segments between those points.[13] The components of a graph can be generalized through these interpretations as thetopological connected components of the corresponding space; these are equivalence classes of points that cannot be separated by pairs of disjoint closed sets. Just as the number of connected components of a topological space is an importanttopological invariant, the zerothBetti number, the number of components of a graph is an importantgraph invariant, and intopological graph theory it can be interpreted as the zeroth Betti number of the graph.[3]
The number of components arises in other ways in graph theory as well. Inalgebraic graph theory it equals the multiplicity of 0 as aneigenvalue of theLaplacian matrix of a finite graph.[14] It is also the index of the first nonzero coefficient of thechromatic polynomial of the graph, and the chromatic polynomial of the whole graph can be obtained as the product of the polynomials of its components.[15] Numbers of components play a key role inTutte's theorem on perfect matchings characterizing finite graphs that haveperfect matchings[16] and the associatedTutte–Berge formula for the size of amaximum matching,[17] and in the definition ofgraph toughness.[18]
It is straightforward to compute the components of a finite graph in linear time (in terms of the numbers of the vertices and edges of the graph) using eitherbreadth-first search ordepth-first search. In either case, a search that begins at some particularvertex will find the entire componentcontaining (and no more) before returning. All components of a graph can be found by looping through its vertices, starting a new breadth-first or depth-first search whenever the loop reaches a vertex that has not already been included in a previously found component.Hopcroft & Tarjan (1973) describe essentially this algorithm, and state that it was already "well known".[19]
Connected-component labeling, a basic technique in computerimage analysis, involves the construction of a graph from the image and component analysis on the graph.The vertices are the subset of thepixels of the image, chosen as being of interest or as likely to be part of depicted objects. Edges connectadjacent pixels, with adjacency defined either orthogonally according to theVon Neumann neighborhood, or both orthogonally and diagonally according to theMoore neighborhood. Identifying the connected components of this graph allows additional processing to find more structure in those parts of the image or identify what kind of object is depicted. Researchers have developed component-finding algorithms specialized for this type of graph, allowing it to be processed in pixel order rather than in the more scattered order that would be generated by breadth-first or depth-first searching. This can be useful in situations where sequential access to the pixels is more efficient than random access, either because the image is represented in a hierarchical way that does not permit fast random access or because sequential access produces bettermemory access patterns.[20]
There are also efficient algorithms to dynamically track the components of a graph as vertices and edges are added, by using adisjoint-set data structure to keep track of the partition of the vertices into equivalence classes, replacing any two classes by their union when an edge connecting them is added. These algorithms takeamortized time per operation, where adding vertices and edges and determining the component in which a vertex falls are both operations, and is a very slowly growing inverse of the very quickly growingAckermann function.[21] One application of this sort of incremental connectivity algorithm is inKruskal's algorithm forminimum spanning trees, which adds edges to a graph in sorted order by length and includes an edge in the minimum spanning tree only when it connects two different components of the previously-added subgraph.[22] When both edge insertions and edge deletions are allowed,dynamic connectivity algorithms can still maintain the same information, in amortized time per change and time per connectivity query,[23] or in near-logarithmic randomizedexpected time.[24]
Components of graphs have been used incomputational complexity theory to study the power ofTuring machines that have a working memory limited to alogarithmic number of bits, with the much larger input accessible only through read access rather than being modifiable. The problems that can be solved by machines limited in this way define thecomplexity classL. It was unclear for many years whether connected components could be found in this model, when formalized as adecision problem of testing whether two vertices belong to the same component, and in 1982 a related complexity class,SL, was defined to include this connectivity problem and any other problem equivalent to it under logarithmic-spacereductions.[25] It was finally proven in 2008 that this connectivity problem can be solved in logarithmic space, and therefore thatSL = L.[26]
In a graph represented as anadjacency list, with random access to its vertices, it is possible to estimate the number of connected components, with constant probability of obtainingadditive (absolute) error at most, insublinear time.[27]

Inrandom graphs the sizes of components are given by arandom variable, which, in turn, depends on the specific model of how random graphs are chosen. In the version of theErdős–Rényi–Gilbert model, a graph on vertices is generated by choosing randomly and independently for each pair of vertices whether to include an edge connecting that pair, withprobability of including an edge and probability of leaving those two vertices without an edge connecting them.[28] The connectivity of this model dependson, and there are three different rangesof with very different behavior from each other. In the analysis below, all outcomes occurwith high probability, meaning that the probability of the outcome is arbitrarily close to one for sufficiently large valuesof. The analysis depends on a parameter, a positive constant independent of that can be arbitrarily close to zero.
In the same model of random graphs, there will exist multiple connected components with high probability for values of below a significantly higher threshold,, and a single connected component for values above the threshold,. This phenomenon is closely related to thecoupon collector's problem: in order to be connected, a random graph needs enough edges for each vertex to be incident to at least one edge. More precisely, if random edges are added one by one to a graph, then with high probability the first edge whose addition connects the whole graph touches the last isolated vertex.[32]
For different models including the random subgraphs of grid graphs, the connected components are described bypercolation theory. A key question in this theory is the existence of apercolation threshold, a critical probability above which a giant component (or infinite component) exists and below which it does not.[33]