Advanced maths

Graph cycle basis calculator from edge list

Construct a spanning-forest fundamental cycle basis or an exact minimum-weight cycle basis for a bounded simple undirected graph.

Your numbers

Labels are 1 through this count. Include isolated vertices.
One undirected from,to,integer weight row. Minimum mode requires nonnegative weights and at most 9 vertices/18 edges.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A graph cycle basis is a collection of edge-incidence vectors that independently generate every even-degree edge set by symmetric difference. This calculator offers one fundamental basis from a spanning forest and, for smaller inputs, a minimum-total-weight basis. Fundamental mode adds each nonforest edge to its unique forest path. Minimum mode enumerates supported simple cycles, sorts by cycle weight and greedily accepts linearly independent incidence vectors over GF(2). The returned basis size is checked against m−n+c, where c includes isolated components.

THE FORMULACycle-space dimension over GF(2) = m − n + c; combine edge sets by symmetric difference.

A worked example

Take a square with four unit-weight boundary edges and a diagonal of weight eight from vertex one to three. There are five edges, four vertices and one component, so the cycle-space dimension is two. The square cycle weighs four. Each diagonal triangle weighs ten. A minimum-weight basis uses the square and one triangle, totaling fourteen. The other triangle is their symmetric difference: shared boundary edges cancel modulo two. A fundamental basis can instead contain both triangles and total twenty; being a valid basis does not make it minimum-weight.

Good to know

Fundamental mode supports simple undirected graphs on 1–40 vertices and at most 200 edges. Minimum mode supports 1–9 vertices and 18 edges with nonnegative whole weights, at most 50,000 candidate cycles and one million enumeration states. Caps produce explicit errors, not partial optimality claims. Edge weights are within ±1,000,000 in fundamental mode. Each cycle contributes its weight separately, so an edge shared between basis cycles is counted once per occurrence. This is not a list of all cycles or an Euler traversal.

Cycle addition means toggling edges rather than adding ordinary vectors of counts

Represent a cycle by a zero or one for every input edge. Adding two such vectors over GF(2) toggles membership: an edge present twice disappears, while an edge present in only one remains. The result can be a disjoint union of cycles rather than one connected simple cycle. This algebraic space is why independence must be checked on edge-incidence rows, not inferred from different vertex sequences or from two drawings that merely look different.

A spanning forest contains n−c edges. Every remaining edge creates exactly one fundamental cycle, giving m−n+c basis cycles. Isolates increase both n and c, leaving the dimension unchanged. A forest has dimension zero and an empty basis, which is a complete result rather than an enumeration failure. The fundamental construction needs no optimization over possible spanning forests and therefore does not promise the lightest basis.

A unit square and one weight-ten diagonal triangle form a minimum cycle basis123411118Square weight: 4Triangle weight: 10Minimum total: 14
The square boundary weighs 4 and each diagonal triangle weighs 10 because the diagonal has weight 8. Two independent cycles are needed: 5−4+1=2. Minimum total basis weight is 4+10=14.

Minimum basis weight is not the weight of a minimum spanning tree

For the bounded minimum mode, simple-cycle candidates are ordered by their full edge-weight sum. A candidate is accepted only if it adds a new GF(2) pivot after reduction against already selected vectors. This greedy rule applies to the linear-independence structure of the cycle space. Ties can lead to several equally good bases, so a different valid cycle list can still have the same optimum total weight.

The output includes both ordered closed vertex walks and the unordered input-edge identities used in the independence test. Those representations answer different checking needs; sorting edge IDs alone does not turn them into a traversal order. The Minimum spanning tree calculator from weighted edges removes cycles to connect vertices cheaply, whereas this page deliberately retains enough independent cycles to generate the cycle space. Neither an arbitrary cycle basis nor a shortest-path tree should be mislabeled as the minimum basis without the weight optimization.

A few questions, answered

Must every basis cycle be edge-disjoint?

No. Cycles may share edges. Independence means no nonempty GF(2) combination of their incidence vectors gives the zero vector.

Does the table enumerate all simple cycles?

No. It returns an independent generating basis. Minimum mode can inspect many more candidates internally, but only the selected basis is displayed.

Find your calculator

Start typing to explore the library.