Advanced maths

Acyclic vertex coloring calculator with no bichromatic cycles

Find the smallest proper vertex coloring whose every two-color induced subgraph is a forest.

Your numbers

Zero-based labels 0 through n−1, including isolated vertices.
One row: u v. No loops or duplicate unordered pairs.

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

Find the smallest proper vertex coloring whose every two-color induced subgraph is a forest.

THE FORMULAχ_a(G)=min k: c(u)≠c(v) for uv∈E and G[c^{-1}({i,j})] is a forest for every i<j.

A worked example

The square is properly two-colorable, but those two colors induce a cycle. Colors [0,1,0,2] break every bichromatic cycle, so its acyclic color count is 3.

Good to know

Simple undirected graphs on 1–10 vertices. Exact canonical-color search across increasing color counts with 2,000,000 partial-state cap. Proper-edge and pairwise forest certificates. One optimum, no prescribed palette, balanced classes, star-coloring or distance-two-coloring claim. Cutoff is unresolved.

Proper coloring with a stronger cycle restriction

A proper vertex coloring gives adjacent vertices different colors. An acyclic coloring additionally requires every subgraph induced by any two color classes to be a forest. In other words, a cycle that alternates between just two colors is forbidden, even though each individual edge is properly colored.

Cycles involving three or more colors are allowed. The goal is to use the fewest colors under that specific extra restriction, not to make the graph itself acyclic. A graph can retain all of its original cycles while admitting a small acyclic coloring.

The square is properly two-colorable, but those two colors induce a cycle0123Colors: 0, 1, 0, 2Two colors fail:the square survivesThree colors workEvery color pair: forest
Scroll across to see the full diagram.
The square is properly two-colorable, but those two colors induce a cycle. Colors [0,1,0,2] break every bichromatic cycle, so its acyclic color count is 3.

Compare this with the Equitable graph coloring calculator with balanced color classes. Find a smallest proper coloring in which every two-color induced subgraph is a forest; balancing color-class sizes is a different constraint.

Enter vertices and undirected edges

Declare the vertex count and list each simple undirected edge once, using labels zero through n minus one. Every declared vertex receives a color, including isolates. Directed cycles, loops and repeated unordered pairs are rejected because the page implements an undirected simple-graph definition.

The displayed color numbers are names rather than quantities. Exchanging color zero with color one leaves the coloring equally valid. A class can contain several nonadjacent vertices, but its size does not need to match the sizes of other classes; balancing class sizes is a separate equitable-coloring constraint.

Exact search and partial forest checks

The search tries one color, then two, and continues until a valid coloring is found. Vertices are assigned in a degree-based order, while canonical first-use color labels avoid exploring every renaming of the same partial coloring. Adjacent vertices can never share the currently proposed color.

After each assignment, the algorithm checks the affected two-color subgraphs for cycles using disjoint-set connectivity. Adding an edge whose endpoints were already connected would complete a cycle and invalidate that partial assignment. Early rejection is safe because assigning more vertices cannot remove a cycle already present in an induced color pair.

Why the default square needs three colors

The four-cycle can be properly colored with two alternating colors, but those two color classes induce the entire four-cycle. That violates the forest requirement. One color is impossible because the graph has edges, so the acyclic color count must be at least three.

Coloring vertices [0,1,2,3] as [0,1,0,2] uses three colors. Each color pair induces a path or a collection of edges and isolated vertices, never a cycle. The minimum is therefore three. The example highlights exactly why an ordinary bipartite test does not solve the acyclic-coloring problem.

Verify each two-color forest

The result lists the color of every original vertex, the associated classes and a certificate for each pair of colors. For a forest, the number of connected components equals its vertex count minus its edge count. These counts help explain what the forest test found rather than merely reporting a Boolean verdict.

First verify proper coloring on every original edge, then inspect every pair of used colors. Testing only one pair is insufficient when three or more colors appear. Isolated vertices contribute to the component count but cannot introduce a cycle, so they must not be mistaken for a failed or incomplete forest certificate.

Bounds and incomplete-search behavior

This page supports at most ten vertices and uses a fixed search-state budget across all attempted color counts. A completed first success proves that smaller color counts have been ruled out by exhaustive search. The finite size cap keeps the exact problem suitable for an interactive calculator.

If the state budget is exhausted, the run stops explicitly without claiming a chromatic value. A partial coloring is not an upper-bound certificate for the whole graph, and a failed partial branch does not disprove a color count by itself. The result is reported only after the necessary complete search and witness checks finish.

Separate acyclic coloring from related concepts

An acyclic coloring does not require each color pair to form a star forest, which would be the stronger star-coloring condition. It also does not require vertices at distance two to have different colors. Those nearby definitions impose different local structures and generally have different minimum color counts.

Use the computed classes only for applications whose constraints match the no-bichromatic-cycle model. If a downstream process requires balanced loads, prescribed colors or a fixed palette at each vertex, those additional restrictions are absent here. The returned optimum describes the declared graph problem, not every scheduling or labeling requirement suggested by the drawing.

A few questions, answered

Why can a bipartite graph need three acyclic colors?

A two-colorable graph can contain an even cycle, and that whole cycle becomes bichromatic under its proper two-coloring.

Are all cycles forbidden?

No. Only cycles using two colors are forbidden; cycles using three or more colors may remain.

Do color numbers have an ordering meaning?

No. They are class labels, and permuting the color names preserves the same coloring.

Is this star coloring?

No. Star coloring imposes a stronger restriction on each two-color subgraph than merely being a forest.

Find your calculator

Start typing to explore the library.