In graph theory, a branch of mathematics, the circuit rank, cyclomatic number, cycle rank, or nullity of an undirected graph is the minimum number of edges that must be removed from the graph to break all its cycles, making it into a tree or forest. It is equal to the number of independent cycles in the graph (the size of a cycle basis). Unlike the corresponding feedback arc set problem for directed graphs, the circuit rank is easily computed using the formula
r=m-n+c
The circuit rank can be explained in terms of algebraic graph theory as the dimension of the cycle space of a graph, in terms of matroid theory as the corank of a graphic matroid, and in terms of topology as one of the Betti numbers of a topological space derived from the graph. It counts the ears in an ear decomposition of the graph, forms the basis of parameterized complexity on almost-trees, and has been applied in software metrics as part of the definition of cyclomatic complexity of a piece of code. Under the name of cyclomatic number, the concept was introduced by Gustav Kirchhoff.
The circuit rank of a graph may be described using matroid theory as the corank of the graphic matroid of .[2] Using the greedy property of matroids, this means that one can find a minimum set of edges that breaks all cycles using a greedy algorithm that at each step chooses an edge that belongs to at least one cycle of the remaining graph.
Alternatively, a minimum set of edges that breaks all cycles can be found by constructing a spanning forest of and choosing the complementary set of edges that do not belong to the spanning forest.
In algebraic graph theory, the circuit rank is also the dimension of the cycle space of
G
This count of independent cycles can also be explained using homology theory, a branch of topology. Any graph may be viewed as an example of a 1-dimensional simplicial complex, a type of topological space formed by representing each graph edge by a line segment and gluing these line segments together at their endpoints.The cyclomatic number is the rank of the first (integer) homology group of this complex,[3]
r=\operatorname{rank}\left[H1(G,\Z)\right].
A variant of the circuit rank for planar graphs, normalized by dividing by the maximum possible circuit rank of any planar graph with the same vertex set, is called the meshedness coefficient. For a connected planar graph with edges and vertices, the meshedness coefficient can be computed by the formula[4]
m-n+1 | |
2n-5 |
.
m-n+1
2n-5
The circuit rank controls the number of ears in an ear decomposition of a graph, a partition of the edges of the graph into paths and cycles that is useful in many graph algorithms.In particular, a graph is 2-vertex-connected if and only if it has an open ear decomposition. This is a sequence of subgraphs, where the first subgraph is a simple cycle, the remaining subgraphs are all simple paths, each path starts and ends on vertices that belong to previous subgraphs,and each internal vertex of a path appears for the first time in that path. In any biconnected graph with circuit rank
r
r
A graph with cyclomatic number
r
Several authors have studied the parameterized complexity of graph algorithms on r-near-trees, parameterized by
r
The cycle rank is an invariant of directed graphs that measures the level of nesting of cycles in the graph. It has a more complicated definition than circuit rank (closely related to the definition of tree-depth for undirected graphs) and is more difficult to compute. Another problem for directed graphs related to the circuit rank is the minimum feedback arc set, the smallest set of edges whose removal breaks all directed cycles. Both cycle rank and the minimum feedback arc set are NP-hard to compute.
It is also possible to compute a simpler invariant of directed graphs by ignoring the directions of the edges and computing the circuit rank of the underlying undirected graph. This principle forms the basis of the definition of cyclomatic complexity, a software metric for estimating how complicated a piece of computer code is.
In the fields of chemistry and cheminformatics, the circuit rank of a molecular graph (the number of rings in the smallest set of smallest rings) is sometimes referred to as the Frèrejacque number.
Some computational problems on graphs are NP-hard in general, but can be solved in polynomial time for graphs with a small circuit rank. An example is the path reconfiguration problem.
Other numbers defined in terms of deleting things from graphs are: