# Cycle basis

In graph theory, a branch of mathematics, a cycle basis of an undirected graph is a set of simple cycles that forms a basis of the cycle space of the graph. That is, it is a minimal set of cycles that allows every even-degree subgraph to be expressed as a symmetric difference of basis cycles.
A fundamental cycle basis may be formed from any spanning tree or spanning forest of the given graph, by selecting the cycles formed by the combination of a path in the tree and a single edge outside the tree. Alternatively, if the edges of the graph have positive weights, the minimum weight cycle basis may be constructed in polynomial time.
In planar graphs, the set of bounded cycles of an embedding of the graph forms a cycle basis. The minimum weight cycle basis of a planar graph corresponds to the Gomory–Hu tree of the dual graph.

## Definitions

A spanning subgraph of a given graph G has the same set of vertices as G itself but, possibly, fewer edges. A graph G, or one of its subgraphs, is said to be Eulerian if each of its vertices has even degree (its number of incident edges). Every simple cycle in a graph is an Eulerian subgraph, but there may be others. The cycle space of a graph is the collection of its Eulerian subgraphs. It forms a vector space over the two-element finite field. The vector addition operation is the symmetric difference of two or more subgraphs, which forms another subgraph consisting of the edges that appear an odd number of times in the arguments to the symmetric difference operation.
A cycle basis is a basis of this vector space in which each basis vector represents a simple cycle. It consists of a set of cycles that can be combined, using symmetric differences, to form every Eulerian subgraph, and that is minimal with this property. Every cycle basis of a given graph has the same number of cycles, which equals the dimension of its cycle space. This number is called the circuit rank of the graph, and it equals $m-n+c$ where $m$ is the number of edges in the graph, $n$ is the number of vertices, and $c$ is the number of connected components.

## Special cycle bases

Several special types of cycle bases have been studied, including the fundamental cycle bases, weakly fundamental cycle bases, sparse (or 2-) cycle bases, and integral cycle bases.

### Induced cycles

Every graph has a cycle basis in which every cycle is an induced cycle. In a 3-vertex-connected graph, there always exists a basis consisting of peripheral cycles, cycles whose removal does not separate the remaining graph. In any graph other than one formed by adding one edge to a cycle, a peripheral cycle must be an induced cycle.

### Fundamental cycles

If $T$ is a spanning tree or spanning forest of a given graph $G$, and $e$ is an edge that does not belong to $T$, then the fundamental cycle $C_{e}$ defined by $e$ is the simple cycle consisting of $e$ together with the path in $T$ connecting the endpoints of $e$. There are exactly $m-n+c$ fundamental cycles, one for each edge that does not belong to $T$. Each of them is linearly independent from the remaining cycles, because it includes an edge $e$ that is not present in any other fundamental cycle. Therefore, the fundamental cycles form a basis for the cycle space. A cycle basis constructed in this way is called a fundamental cycle basis or strongly fundamental cycle basis.
It is also possible to characterize fundamental cycle bases without specifying the tree for which they are fundamental. There exists a tree for which a given cycle basis is fundamental if and only if each cycle contains an edge that is not included in any other basis cycle, that is, each cycle is independent of others. It follows that a collection of cycles is a fundamental cycle basis of $G$ if and only if it has the independence property and has the correct number of cycles to be a basis of $G$.

### Weakly fundamental cycles

A cycle basis is called weakly fundamental if its cycles can be placed into a linear ordering such that each cycle includes at least one edge that is not included in any earlier cycle. A fundamental cycle basis is automatically weakly fundamental (for any edge ordering). If every cycle basis of a graph is weakly fundamental, the same is true for every minor of the graph. Based on this property, the class of graphs (and multigraphs) for which every cycle basis is weakly fundamental can be characterized by five forbidden minors: the graph of the square pyramid, the multigraph formed by doubling all edges of a four-vertex cycle, two multigraphs formed by doubling two edges of a tetrahedron, and the multigraph formed by tripling the edges of a triangle.

### Face cycles

If a connected finite planar graph is embedded into the plane, each face of the embedding is bounded by a cycle of edges. One face is necessarily unbounded (it includes points arbitrarily far from the vertices of the graph) and the remaining faces are bounded. By Euler's formula for planar graphs, there are exactly $m-n+1$ bounded faces. The symmetric difference of any set of face cycles is the boundary of the corresponding set of faces, and different sets of bounded faces have different boundaries, so it is not possible to represent the same set as a symmetric difference of face cycles in more than one way; this means that the set of face cycles is linearly independent. As a linearly independent set of enough cycles, it necessarily forms a cycle basis. It is always a weakly fundamental cycle basis, and is fundamental if and only if the embedding of the graph is outerplanar.
For graphs properly embedded onto other surfaces so that all faces of the embedding are topological disks, it is not in general true that there exists a cycle basis using only face cycles. The face cycles of these embeddings generate a proper subset of all Eulerian subgraphs. The homology group $H_{2}(S,\mathbb {Z} _{2})$ of the given surface $S$ characterizes the Eulerian subgraphs that cannot be represented as the boundary of a set of faces. Mac Lane's planarity criterion uses this idea to characterize the planar graphs in terms of the cycle bases: a finite undirected graph is planar if and only if it has a sparse cycle basis or 2-basis, a basis in which each edge of the graph participates in at most two basis cycles. In a planar graph, the cycle basis formed by the set of bounded faces is necessarily sparse, and conversely, a sparse cycle basis of any graph necessarily forms the set of bounded faces of a planar embedding of its graph.

### Integral bases

The cycle space of a graph may be interpreted using the theory of homology as the homology group $H_{1}(G,\mathbb {Z} _{2})$ of a simplicial complex with a point for each vertex of the graph and a line segment for each edge of the graph. This construction may be generalized to the homology group $H_{1}(G,R)$ over an arbitrary ring $R$. An important special case is the ring of integers, for which the homology group $H_{1}(G,\mathbb {Z} )$ is a free abelian group, a subgroup of the free abelian group generated by the edges of the graph. Less abstractly, this group can be constructed by assigning an arbitrary orientation to the edges of the given graph; then the elements of $H_{1}(G,\mathbb {Z} )$ are labelings of the edges of the graph by integers with the property that, at each vertex, the sum of the incoming edge labels equals the sum of the outgoing edge labels. The group operation is addition of these vectors of labels. An integral cycle basis is a set of simple cycles that generates this group.

## Minimum weight

If the edges of a graph are given real number weights, the weight of a subgraph may be computed as the sum of the weights of its edges. The minimum weight basis of the cycle space is necessarily a cycle basis: by Veblen's theorem, every Eulerian subgraph that is not itself a simple cycle can be decomposed into multiple simple cycles, which necessarily have smaller weight.
By standard properties of bases in vector spaces and matroids, the minimum weight cycle basis not only minimizes the sum of the weights of its cycles, it also minimizes any other monotonic combination of the cycle weights. For instance, it is the cycle basis that minimizes the weight of its longest cycle.

### Polynomial time algorithms

In any vector space, and more generally in any matroid, a minimum weight basis may be found by a greedy algorithm that considers potential basis elements one at a time, in sorted order by their weights, and that includes an element in the basis when it is linearly independent of the previously chosen basis elements. Testing for linear independence can be done by Gaussian elimination. However, an undirected graph may have an exponentially large set of simple cycles, so it would be computationally infeasible to generate and test all such cycles.
Horton (1987) provided the first polynomial time algorithm for finding a minimum weight basis, in graphs for which every edge weight is positive. His algorithm uses this generate-and-test approach, but restricts the generated cycles to a small set of $O(mn)$ cycles, called Horton cycles. A Horton cycle is a fundamental cycle of a shortest path tree of the given graph. There are at most n different shortest path trees (one for each starting vertex) and each has fewer than m fundamental cycles, giving the bound on the total number of Horton cycles. As Horton showed, every cycle in the minimum weight cycle basis is a Horton cycle. Using Dijkstra's algorithm to find each shortest path tree and then using Gaussian elimination to perform the testing steps of the greedy basis algorithm leads to a polynomial time algorithm for the minimum weight cycle basis. Subsequent researchers have developed improved algorithms for this problem, reducing the worst-case time complexity for finding a minimum weight cycle basis in a graph with $m$ edges and $n$ vertices to $O(m^{2}n/\log n)$.

### NP-hardness

Finding the fundamental basis with the minimum possible weight is closely related to the problem of finding a spanning tree that minimizes the average of the pairwise distances; both are NP-hard. Finding a minimum weight weakly fundamental basis is also NP-hard, and approximating it is MAXSNP-hard. If negative weights and negatively weighted cycles are allowed, then finding a minimum cycle basis (without restriction) is also NP-hard, as it can be used to find a Hamiltonian cycle: if a graph is Hamiltonian, and all edges are given weight −1, then a minimum weight cycle basis necessarily includes at least one Hamiltonian cycle.

### In planar graphs

The minimum weight cycle basis for a planar graph is not necessarily the same as the basis formed by its bounded faces: it can include cycles that are not faces, and some faces may not be included as cycles in the minimum weight cycle basis. However, there exists a minimum weight cycle basis in which no two cycles cross each other: for every two cycles in the basis, either the cycles enclose disjoint subsets of the bounded faces, or one of the two cycles encloses the other one. This set of cycles corresponds, in the dual graph of the given planar graph, to a set of cuts that form a Gomory–Hu tree of the dual graph, the minimum weight basis of its cut space. Based on this duality, an implicit representation of the minimum weight cycle basis in a planar graph can be constructed in time $O(n\log ^{3}n)$.

## Applications

Cycle bases have been used for solving periodic scheduling problems, such as the problem of determining the schedule for a public transportation system. In this application, the cycles of a cycle basis correspond to variables in an integer program for solving the problem.
In the theory of structural rigidity and kinematics, cycle bases are used to guide the process of setting up a system of non-redundant equations that can be solved to predict the rigidity or motion of a structure. In this application, minimum or near-minimum weight cycle bases lead to simpler systems of equations.
In distributed computing, cycle bases have been used to analyze the number of steps needed for an algorithm to stabilize.
In bioinformatics, cycle bases have been used to determine haplotype information from genome sequence data. Cycle bases have also been used to analyze the tertiary structure of RNA.
The minimum weight cycle basis of a nearest neighbor graph of points sampled from a three-dimensional surface can be used to obtain a reconstruction of the surface.
In cheminformatics, the minimal cycle basis of a molecular graph is referred to as the smallest set of smallest rings.