{
  "id": "strongly-connected-component",
  "title": "Strongly Connected Component",
  "lang": "en",
  "source_lang": "en",
  "summary": "A strongly connected component is a maximal set of vertices in a directed graph in which every vertex is reachable from every other vertex.",
  "category": "mathematics",
  "subcategory": "discrete-logic",
  "type": "concept",
  "aliases": [
    "SCC",
    "strong component"
  ],
  "generated_at": "2026-11-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/strongly-connected-component/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/strongly-connected-component/",
      "json": "https://aiwiki.page/zh/strongly-connected-component.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A strongly connected component (SCC) of a directed graph is a maximal set of vertices such that every vertex in the set can be reached from every other vertex by following directed edges. Strongly connected components divide a graph into nonoverlapping regions of mutual reachability. Contracting each component to a single vertex produces a directed acyclic graph, separating the graph’s internal cyclic structure from the one-way connections between its components."
    },
    {
      "heading": "Definition",
      "text": "Let \\(G=(V,E)\\) be a directed graph. Write \\(u\\leadsto v\\) when there is a directed path from vertex \\(u\\) to vertex \\(v\\). Paths of length zero are allowed, so every vertex reaches itself.\n\nDefine a relation on \\(V\\) by\n\n\\[u\\sim v \\quad\\Longleftrightarrow\\quad u\\leadsto v\\ \\text{and}\\ v\\leadsto u.\\]\n\nThis is an equivalence relation:\n\n- Reflexivity: each vertex reaches itself.\n- Symmetry: mutual reachability is symmetric by definition.\n- Transitivity: if \\(u\\) and \\(v\\) are mutually reachable, and \\(v\\) and \\(w\\) are mutually reachable, concatenating paths establishes mutual reachability between \\(u\\) and \\(w\\).\n\nThe strongly connected components are the equivalence classes of this relation. They therefore form a unique partition of the vertex set.\n\nEquivalently, an SCC is a nonempty set \\(C\\subseteq V\\) whose induced subgraph is strongly connected and which is maximal under inclusion with that property. Maximal does not mean largest: a graph may contain many SCCs of different sizes, none of which can be enlarged while remaining strongly connected.\n\nAlthough reachability is initially defined using paths in the entire graph, paths between vertices of one component cannot leave that component and later return. Any intermediate vertex on such a path is mutually reachable with the endpoints and therefore belongs to the same component.\n\nThe usual algorithmic setting assumes a finite graph. The equivalence-relation definition also applies to infinite directed graphs."
    },
    {
      "heading": "Examples and basic properties",
      "text": "Consider a graph with vertices \\(a,b,c,d,e\\) and edges\n\n\\[a\\to b,\\quad b\\to c,\\quad c\\to a,\\quad c\\to d,\\quad d\\to e,\\quad e\\to d.\\]\n\nIts SCCs are\n\n\\[\\{a,b,c\\} \\quad\\text{and}\\quad \\{d,e\\}.\\]\n\nThe first three vertices form a directed cycle, as do the last two. The edge \\(c\\to d\\) allows travel from the first component to the second, but no path returns. Consequently, the two sets do not combine into a single component.\n\nSeveral consequences follow directly from the definition:\n\n- Every vertex belongs to exactly one SCC.\n- A singleton vertex is an SCC if it is not mutually reachable with any other vertex, whether or not it has a self-loop.\n- A nonempty graph is strongly connected precisely when it has one SCC.\n- Every directed cycle lies entirely within one SCC.\n- Every SCC containing at least two vertices contains a directed cycle.\n- Reversing every edge preserves the SCC partition, because it reverses reachability in both directions.\n\nStrong connectivity does not require a direct edge between every pair of vertices. It also does not require a single simple directed cycle passing through every vertex: several cycles may overlap at shared vertices and together form one SCC.\n\nStrong connectivity differs from weak connectivity, which ignores edge directions. A weakly connected directed graph can contain many SCCs. In an undirected graph, or a directed graph obtained by replacing every undirected edge with edges in both directions, strong components coincide with ordinary connected components."
    },
    {
      "heading": "Condensation graph",
      "text": "The condensation graph of \\(G\\) has one vertex for each SCC. It contains an edge \\(C\\to D\\), for distinct components \\(C\\) and \\(D\\), whenever the original graph contains an edge from a vertex of \\(C\\) to a vertex of \\(D\\). Internal edges are omitted, and duplicate edges are usually merged.\n\nThe condensation graph is always acyclic. If distinct components lay on a directed cycle, every vertex in each of those components could reach every vertex in all the others. They would therefore be one component, contradicting their distinctness.\n\nCondensation preserves reachability between components: a path from component \\(C\\) to component \\(D\\) exists in the condensation exactly when a vertex of \\(C\\) can reach a vertex of \\(D\\) in the original graph. Reachability consequently defines a partial order on the components.\n\nA topological ordering of the condensation arranges the components so that every edge between components points forward. This supports computations that process dependencies component by component while treating cyclic dependencies within a component separately.\n\nA component with no outgoing edge to another component is called a sink component; one with no incoming edge from another component is a source component. Every nonempty finite directed graph has at least one of each."
    },
    {
      "heading": "Algorithms",
      "text": "Several algorithms compute all SCCs in\n\n\\[O(|V|+|E|)\\]\n\ntime using adjacency-list representations. In asymptotic notation, this is linear in the graph’s representation size. The classical methods use depth-first search (DFS).\n\nKosaraju–Sharir algorithm\n\nThe Kosaraju–Sharir algorithm uses two DFS passes:\n\n- Run DFS over the original graph, recording vertices in order of completion.\n- Reverse every edge to obtain the transpose graph.\n- Run DFS over the transpose, considering starting vertices in decreasing order of their completion times from the first pass.\n\nEach DFS tree in the second pass gives one SCC. Vertices already visited in that pass are skipped.\n\nThe ordering ensures that each search enters an unvisited component from which it cannot escape into another unvisited component in the transpose. With this orientation of the two passes, components are discovered in a topological order of the original condensation graph. An equivalent variant performs the first pass on the transpose and the second on the original graph.\n\nThe algorithm is conceptually simple, but requires access to incoming as well as outgoing adjacency, or construction of the transpose.\n\nTarjan’s algorithm\n\nTarjan’s SCC algorithm, published in 1972, uses one DFS traversal and a stack of vertices whose components have not yet been completed.\n\nEach vertex \\(v\\) receives:\n\n- a discovery index \\(\\operatorname{index}(v)\\);\n- a low-link value \\(\\operatorname{low}(v)\\);\n- a marker indicating whether it remains on the stack.\n\nInitially,\n\n\\[\\operatorname{low}(v)=\\operatorname{index}(v).\\]\n\nWhen processing an edge \\(v\\to w\\):\n\n- If \\(w\\) is unvisited, recursively visit it and update\n\n\\[\\operatorname{low}(v) \\leftarrow \\min\\bigl(\\operatorname{low}(v),\\operatorname{low}(w)\\bigr).\\]\n- Otherwise, if \\(w\\) is still on the stack, update\n\n\\[\\operatorname{low}(v) \\leftarrow \\min\\bigl(\\operatorname{low}(v),\\operatorname{index}(w)\\bigr).\\]\n- If \\(w\\) has already been assigned to a completed component, the edge does not affect the low-link value.\n\nAfter all outgoing edges of \\(v\\) have been processed, the condition\n\n\\[\\operatorname{low}(v)=\\operatorname{index}(v)\\]\n\nidentifies the root of an SCC. Vertices are popped from the stack through \\(v\\), inclusive, and assigned to that component.\n\nThe stack-membership test is essential: reaching a vertex in an already completed SCC does not establish mutual reachability. Tarjan’s algorithm emits components in reverse topological order of the condensation.\n\nPractical considerations\n\nBoth algorithms use \\(O(|V|)\\) auxiliary space beyond graph storage, though constructing a transpose may require an additional \\(O(|V|+|E|)\\) representation. Recursive DFS can exhaust a programming language’s call stack on deep graphs; explicit-stack implementations avoid that limitation.\n\nThe linear-time bound depends on representation. Scanning an adjacency matrix generally takes \\(O(|V|^2)\\) time, even for a sparse graph.\n\nFor testing whether a nonempty graph is strongly connected, a simpler method suffices: choose a vertex, check that it reaches every vertex, then repeat from the same vertex with all edges reversed. Both checks succeed exactly when the graph is strongly connected."
    },
    {
      "heading": "Applications",
      "text": "Dependency analysis and formal verification\n\nIn software dependency graphs, SCCs identify groups of mutually dependent modules, functions, or variables. A nontrivial component indicates a cyclic dependency, but does not by itself establish an error. The condensation organizes these groups into an acyclic dependency structure.\n\nIn formal verification, reachable SCCs help analyze recurring behavior in finite-state systems. A component containing a directed cycle can support an infinite execution that remains within it. Further conditions are needed when a specification requires particular accepting states, transitions, or fairness constraints.\n\nBoolean satisfiability\n\nSCC decomposition provides a linear-time method for 2-satisfiability (2-SAT). For a formula expressed as a conjunction of two-literal clauses, each clause\n\n\\[(a\\lor b)\\]\n\nproduces implication edges\n\n\\[\\neg a\\to b, \\qquad \\neg b\\to a.\\]\n\nThe formula is satisfiable if and only if no variable and its negation belong to the same SCC of the resulting implication graph. A satisfying assignment, when one exists, can be constructed using an ordering of the components.\n\nMarkov chains\n\nFor a finite Markov chain, form a graph with an edge \\(i\\to j\\) whenever the corresponding entry of the transition matrix is positive. Its SCCs are the chain’s communicating classes.\n\nSink components correspond to closed communicating classes: once the chain enters one, it cannot leave. In a finite chain, states in these closed classes are recurrent, whereas states outside them are transient. Strong connectivity of the entire transition graph is equivalent to irreducibility, but does not imply aperiodicity.\n\nMatrix structure\n\nGiven a square matrix, construct a graph with an edge \\(i\\to j\\) whenever the entry \\(a_{ij}\\) is nonzero. Ordering the SCCs topologically and applying the same permutation to rows and columns places the matrix in block upper-triangular form. The diagonal blocks correspond to SCCs.\n\nThis structural decomposition can expose independent or sequentially dependent parts of a system of linear equations, and is useful in sparse numerical computation."
    },
    {
      "heading": "Scope and limitations",
      "text": "Strongly connected components describe directed reachability, not distance, connection strength, or robustness. A component can be strongly connected while relying on a single crucial edge or vertex. Edge weights do not affect the decomposition unless they determine whether an edge exists.\n\nSCCs also differ from statistical or community-based clusters. One-way edges may connect distinct SCCs very densely, while a large SCC may contain regions joined by only a few links.\n\nThe classical algorithms compute a static decomposition. Adding an edge can merge several components if it creates a return path between them; deleting an edge can split a component. Maintaining SCCs efficiently under repeated updates requires specialized dynamic algorithms."
    }
  ],
  "links": [
    "directed-graph",
    "directed-acyclic-graph",
    "equivalence-relation",
    "equivalence-class",
    "set-partition",
    "partial-order",
    "algorithm",
    "big-o-notation",
    "depth-first-search",
    "kosaraju-sharir-algorithm",
    "adjacency-matrix",
    "formal-verification",
    "markov-chain",
    "transition-matrix",
    "matrix",
    "system-of-linear-equations",
    "cluster-analysis"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}