How this calculation works
Find a vertex order that makes first-fit greedy coloring use as many colors as possible, with a step-by-step witness.
Gamma(G)=max over vertex orders pi of the number of colors used by first-fit coloring in order pi.A worked example
The path0–1–2–3 has chromatic number2 but Grundy number3. Processing vertices0,3,1,2 produces colors0,0,1,2 in processing order.
Good to know
Simple graphs on1–9vertices. Complete permutation enumeration or equivalent exact Grundy-coloring search under a fixed state cap; report color assigned at each step and a neighbor of every smaller color. Exhaustion is unresolved, not a best-found maximum.
Reference: SageMath graph_coloring.grundy_coloring documentation (opens in a new tab) ↗
Worst order is a different question
A proper vertex coloring gives adjacent vertices different colors. The chromatic number minimizes how many colors are needed. The Grundy number instead asks how badly the first-fit greedy rule can perform when the vertex order is chosen adversarially. A graph with a small chromatic number can still have an ordering that makes that simple rule introduce more colors.
First-fit always assigns the smallest nonnegative color absent from the already processed neighbors. There is no freedom to choose a larger color merely because it would make the objective better. The only optimization variable is the order of the vertices. Keeping this rule explicit distinguishes a genuine worst-case greedy coloring from an arbitrary proper coloring with unnecessarily many labels.
Compare this with the Chromatic polynomial calculator from a graph edge list. Maximize the number of colors produced by first-fit greedy coloring over all vertex orders and return a replayable worst-case order. Existing chromatic analysis minimizes proper colors; the new output measures adversarial greedy-order sensitivity.
Describe the graph and vertex labels
Enter the declared number of vertices and simple undirected edge pairs. Labels identify vertices throughout the returned order and color table. Loops make proper coloring impossible under the stated model, while repeated pairs do not provide additional constraints and are rejected. Isolates are allowed and always receive color zero when processed.
The exact implementation works on small graphs because the number of possible vertex orders grows factorially. Equivalent exact formulations can reduce repeated work, but a search limit still has to be honored. When a computation is cut off, a discovered order is a lower bound on the worst-case color count rather than a certified maximum. The page should keep those two claims separate.
Replay the greedy rule precisely
Start with every vertex uncolored. At each step, collect colors of that vertex’s neighbors that have already appeared in the order. Choose the first color starting at zero that is not in the collected set. Future neighbors do not affect the current choice. Record the forbidden set and assigned color so the entire coloring can be reconstructed without trusting the search implementation.
A vertex receiving color c must have earlier neighbors using every color0 through c−1. Those neighbors explain why all smaller choices were blocked. It cannot have an earlier neighbor of color c. This local witness is useful when checking a returned order, but local validity alone establishes only that the order attains that many colors; the maximization proof still comes from complete search.
The four-vertex path example
Process vertex0 first. It has no colored neighbor and receives color0. Vertex3 is not adjacent to0 and also receives color0. Next process vertex1, which sees color0 at vertex0, so it receives color1. Finally vertex2 sees color1 at vertex1 and color0 at vertex3, forcing the new color2.
Three colors have therefore been attained. The maximum degree of this path is two, and first-fit can never use more than degree plus one at a vertex. Thus no ordering can use more than three colors here. The displayed ordering reaches that bound, proving Grundy number three even though an alternating two-color assignment proves chromatic number two.
Useful bounds and special cases
For any graph, the Grundy number is at least its chromatic number because every greedy output is a proper coloring. It is at most maximum degree plus one, because a vertex has only that many neighbors capable of blocking smaller colors. These bounds can help check a result, but they need not coincide on an arbitrary graph.
A nonempty edgeless graph has Grundy number one, regardless of vertex order. A complete graph on n vertices has Grundy number n because each new vertex sees every earlier color. These simple families test endpoints of the implementation. Disjoint components can be analyzed separately in principle; the worst color count of their union is the largest component value, not the sum.
Read the order and color arrays together
The returned vertex order is a permutation of the input labels. A color array may instead be indexed by original vertex label. Do not confuse the two arrangements: a sequence of colors in processing order can look different from the same assignments written in vertex order. The table should make this convention explicit and include each vertex exactly once.
Several different orders may attain the same maximum. The calculator can return one canonical or first-found witness without claiming that it is unique. Relabeling the graph preserves the optimum, although it can change tie breaking. Adding edges does not support every naive monotonicity intuition about greedy behavior, so compare actual certificates rather than inferring an ordering from a sketch.
Use the result as an algorithm diagnostic
Grundy analysis measures sensitivity of one specified greedy algorithm to ordering. It does not measure the best color assignment, the quality of a particular practical heuristic, or the number of channel frequencies physically available in an engineering system. To evaluate a chosen heuristic order, replay that order separately and compare its color count with the computed worst case.
The supported small-instance search provides an exact combinatorial result when it finishes. It is not a claim that all large graph orderings can be examined quickly. A cutoff should preserve the distinction between a valid high-color witness and a proven maximum. The step table is the durable part of the answer: it explains exactly where earlier choices forced each additional color.
A few questions, answered
Is the Grundy number the chromatic number?
Not generally. Chromatic number minimizes colors; Grundy number maximizes the colors produced by the specified first-fit rule.
Can I choose a larger color at a step?
No. First-fit must choose the smallest available color; only the vertex order is optimized.
Why does the four-vertex path use three colors?
The order0,3,1,2 makes the last vertex see both colors0 and1, forcing color2.
Does one high-color order prove the maximum?
It proves attainability. An upper bound or completed exact search is also needed to establish the maximum.