Advanced maths

Equitable graph coloring calculator with balanced color classes

Find the smallest number of colors permitting a proper coloring whose color-class sizes differ by at most one.

Your numbers

Vertices are labeled 0 through n−1, including isolated vertices.
One edge per line: u,v. No loops or duplicate pairs. Blank means no 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

Find the smallest number of colors permitting a proper coloring whose color-class sizes differ by at most one. Return the assignment, balanced classes and tested lower-bound information.

THE FORMULAmin k such that uv∈E⇒c(u)≠c(v), and |C_i|∈{floor(n/k),ceil(n/k)} for all k color classes.

A worked example

The four-vertex star is ordinarily two-colorable with classes of sizes 1 and 3, but that coloring is not equitable. Three colors work with sizes 1,2,1 by putting the center alone and splitting the leaves. The minimum equitable color count is 3.

Good to know

Simple undirected graphs with 1–12 vertices. Searches k upward from an exact clique lower bound with exhaustive balanced assignment and color-symmetry pruning. 2000000 search-state cap throws unfinished error. Minimum equitable color count only; not equitable chromatic threshold.

Add fairness to proper coloring

Proper coloring prevents adjacent vertices from sharing a color. Equitable coloring adds a balance requirement: the largest and smallest class sizes may differ by at most one. The calculator seeks the smallest color count satisfying both conditions simultaneously, rather than balancing one arbitrary greedy coloring.

For n vertices and k colors, every class must have either floor(n/k) or ceil(n/k) members. This makes balance exact and discrete. The requirement can increase the number of colors beyond the ordinary chromatic number, especially when a graph forces a very small class in any minimum proper coloring.

The star needs three colors when classes are balancedProper coloring with balanced classes0:A1:B2:B3:CClass A0Class B12Class C3Class sizes 1, 2, 1
Scroll across to see the full diagram.
The four-vertex star is ordinarily two-colorable with classes of sizes 1 and 3, but that coloring is not equitable. Three colors work with sizes 1,2,1 by putting the center alone and splitting the leaves. The minimum equitable color count is 3.

Compare this with the List coloring calculator with allowed colors at each vertex. Find the smallest proper coloring whose class sizes differ by at most one,without per-vertex color lists.

Enter a simple conflict graph

Declare up to twelve vertices and list undirected conflict edges as zero-based endpoint pairs. A missing edge means two vertices may share a class; it does not require them to do so. Isolated declared vertices remain in the balancing totals and can help fill smaller classes.

Loops, duplicate unordered pairs, noninteger labels and endpoints outside the count are rejected. The input does not include vertex weights or class capacities beyond equal cardinality. If tasks have unequal duration or size, equal numbers of vertices do not imply equal workloads, so this model may not represent the intended fairness requirement.

See why the default needs three colors

The default star has center 0 adjacent to leaves 1, 2 and 3. Any proper two-coloring puts the center in one class and all three leaves in the other. Those sizes are one and three, whose difference is two, violating the equitable condition.

With three colors, place the center in a singleton class and split the leaves into a two-vertex class and another singleton. The sizes are one, two and one, so the difference is one. Since one color fails properness and two fail balance, three is the exact minimum equitable count.

Search color counts without monotonic assumptions

The program first finds the largest clique by exhaustive vertex-subset checks. Its size is a valid lower bound on any proper coloring. Starting there, the solver tests successive color counts, checking balance capacities and adjacency constraints together until a feasible assignment is found.

It does not use a binary search or assume that feasibility at one color count automatically settles all larger counts. The minimum equitable color count is distinct from the equitable chromatic threshold, which concerns feasibility at every larger count. This page reports only the first feasible count in the tested ascending sequence.

Follow assignment pruning and proof

Vertices with higher degree are assigned earlier to expose conflicts quickly. Each class is limited to ceil(n/k) members, and a branch is abandoned if the remaining vertices cannot fill all class deficits below floor(n/k). These checks exclude only assignments that cannot meet the final balance condition.

Color names are interchangeable, so newly used colors are introduced in a fixed order. This removes symmetric copies without discarding genuinely different class partitions. A completed unsuccessful search at a smaller k is a proof of infeasibility for that count; a failed greedy attempt alone would not provide that proof.

Inspect the returned classes

The assignment array is indexed by vertex label and contains zero-based color labels. The classes array groups vertices by those labels, while classSizes gives their cardinalities. Check every input edge for different endpoint colors, then compare the smallest and largest class sizes to verify the certificate.

The cliqueLowerBound explains where testing began, and rejectedColorCounts records completed unsuccessful counts before the optimum. These rejected counts can be above the clique bound when balancing adds difficulty. Different optimal balanced partitions may exist, so the displayed class membership is one solution rather than a uniqueness result.

Limits and reference scope

The calculator caps the graph at twelve vertices and recursive assignment work at two million states across tested color counts. Hitting that cap raises an unfinished-search error, preventing a partial assignment or untested minimum claim. The accepted completed result is an exact bounded optimization, not a heuristic estimate.

The linked NetworkX documentation describes an efficient equitable-coloring method with its own sufficient color-count restriction. This implementation instead exhaustively tests small counts and can therefore answer the minimum question for small graphs below that sufficient range. Neither method models weighted balancing, directed conflicts or preassigned colors on this page.

A few questions, answered

Is this ordinary graph coloring?

It also requires all color-class sizes to differ by at most 1.

Why does a star sometimes need extra colors?

Its ordinary bipartition can be too uneven to meet the balance condition.

Is the answer an equitable chromatic threshold?

No. It is the smallest feasible color count, not the first count after which every larger count works.

Does the clique lower bound always equal the answer?

No. Proper-coloring or balance restrictions can force a larger count.

Find your calculator

Start typing to explore the library.