is coloring an image of a flower that has six petals organized in a circle. She desires to paint every of the six petals with precisely one of many following 4 colours: pink, orange, yellow, and blue. No two neighboring petals can have the identical coloration. Not all 4 colours have to be used. What number of methods are there for Rita to paint the flower petals whereas satisfying these constraints? This was the idea of drawback #25 within the 2025 Cayley Contest, and it occurs to be a particular instance of a category of combinatorial knowledge science issues associated to the notion of graph coloring. Within the following sections, we’ll clear up Rita’s concrete drawback, derive its common open and closed-form options, and have a look at some attention-grabbing sensible purposes in trade.
Notice: All figures and formulation within the following sections have been created by the creator of this text.
A Theoretical Puzzle
To resolve Rita’s drawback, allow us to start by visualizing the flower petals as a cyclical graph consisting of 6 nodes linked by edges as proven in Determine 1:

Determine 2 reveals some legitimate colorings (additionally referred to as correct colorings) of the petals:

Let P(n, okay) be the variety of methods we will coloration a cycle of n nodes with okay colours, such that no neighboring nodes have the identical coloration.
Now, contemplate what occurs if we break the cycle into a series of n nodes. What number of methods Pchain(n, okay) are there to paint a series of n nodes with okay colours, such that no neighboring nodes have the identical coloration? For the beginning (left-most) node within the chain, we’ve got a alternative of okay colours. However for every of the next n – 1 nodes, we’ve got a alternative of solely okay – 1 colours, since one of many colours could have already been taken by the previous node. This instinct is illustrated in Determine 3 beneath:

Thus, we’ve got:

Nevertheless, discover that in a few of these legitimate colorings, the primary and final nodes within the chain will share the identical coloration – if we subtract these instances from Pchain(n, okay), then we might acquire P(n, okay) as required. Moreover, discover that the instances to subtract are equal to P(n – 1, okay), i.e., the variety of methods to paint a cycle of n – 1 nodes with okay colours, such that no neighboring nodes have the identical coloration. This so-called deletion-contraction maneuver is illustrated in Determine 4 beneath:

Determine 5 beneath reveals the bottom instances for P(n, okay), for a given worth okay:

Pulling all of those insights collectively yields the next first-order recurrence relation for optimistic integers n > 3 and okay, with base instances as described above:

Now, fixing Rita’s drawback quantities to evaluating the recurrence P(n, okay) for n = 6 and okay = 4. Because the numbers on this case are comparatively small, we will perform the analysis by increasing P(6, 4) as follows:

Utilizing the expression for the bottom case P(3, okay), observe that:

In consequence:

Thus, there are precisely 732 methods for Rita to paint her flower petals whereas satisfying the given constraints.
The next Python operate (appropriate with Python variations ≥ 3.9) operationalizes the recurrence to allow us to rapidly consider P(n, okay) for bigger enter values:
def num_proper_colorings(n: int, okay: int) -> int:
"""
Iteratively compute the variety of correct colorings of a cycle graph with n nodes and okay colours.
Parameters:
- n (int): Variety of nodes within the cycle graph.
- okay (int): Variety of out there colours.
Returns:
- int: Variety of correct colorings.
"""
if n == 1:
return okay
elif n == 2:
return okay * (okay - 1)
elif n == 3:
return okay * (okay - 1) * (okay - 2)
# Initialize base case num_proper_colorings(3, okay)
num_prev = okay * (okay - 1) * (okay - 2)
for i in vary(4, n + 1):
present = okay * (okay - 1)**(i - 1) - num_prev
num_prev = present
return num_prev
Graph coloring may also be operationalized utilizing backtracking, a helpful method for exploring the answer house of assorted varieties of knowledge science issues and incrementally setting up candidate options. This article supplies an intuitive introduction to backtracking, and the next video reveals how backtracking may be utilized to graph coloring issues particularly:
Closed-Kind Resolution
The iterative Python operate proven above has a time complexity of O(n) with respect to variety of nodes n within the cyclical graph. Nevertheless, if we will discover an analytical or closed-form answer to P(n, okay), we might consider the consequence immediately; the corresponding Python operate would have a time complexity of simply O(1) and thus characterize a considerable time saving as n grows very giant. Time complexity and the deserves of closed-form options are mentioned in additional depth in this article on algorithmic considering for knowledge scientists.
To discover a simplified closed-form answer, allow us to rearrange our recurrence relation as follows:

At this level, we will make use of a neat precept in linear algebra: the final answer of a linear algebraic equation f(x) = y is the sum xh + xp of the final answer xh of its homogeneous counterpart f(x) = 0 and a specific answer xp of f(x) = y. To remind ourselves of why this works, we will substitute xh + xp into f(x) = y to get f(xh + xp) = y. Since f(x) is a linear operate, f(xh + xp) = f(xh) + f(xp) = y. We all know that f(xh) = 0 and f(xp) = y. By substitution, f(xh) + f(xp) = 0 + y = y. The equation y = y is trivially true, confirming that xh + xp is certainly the final answer of f(x) = y. Thus, our activity is now to:
- Discover a common answer xh of the homogeneous equation P(n, okay) + P(n – 1, okay) = 0
- Discover a specific answer xp to our recurrence P(n, okay) + P(n – 1, okay) = okay(okay – 1)(n – 1)
- Mix xh and xp to derive the final closed-form answer of our recurrence
So, allow us to begin by fixing the next homogeneous equation:

Notice that, for simplicity, we let:

Every time period appears to cancel the earlier one, so it should alternate in signal at each step, i.e., there exists a relentless time period C (which we’ll derive shortly) such that:

Subsequent, because the right-hand aspect of the unique recurrence is a a number of of (okay – 1)(n – 1), allow us to attempt the next specific answer P‘:

A is a continuing time period that we will derive by plugging P’ into the left-hand aspect of the unique recurrence as follows:

This implies A = 1, so we’ve got:

Combining the actual and homogeneous options offers us:

Now, we will use our base case for n = 3 to derive C:

Substituting C again into the mixed answer offers us the next closed-form answer:

We will confirm that this certainly offers us the right answer for the Cayley contest drawback:

Sensible Purposes
Graph coloring is a elementary drawback in graph idea that includes assigning labels (or “colours”) to the nodes of a graph such that no two adjoining nodes share the identical coloration. In essence, graph coloring makes an attempt to partition a graph into impartial units which may be handled uniformly (i.e., all parts of a set could also be assigned the identical coloration) with out violating adjacency constraints. This sort of drawback framing may be utilized in a variety of information science use instances involving constraint-based optimization and useful resource allocation. We have a look at a few of these purposes beneath.
Scheduling and Timetabling
Graph coloring can be utilized to resolve scheduling issues, the place duties or occasions have to be organized with out conflicts. Graphs used to mannequin such situations are sometimes referred to as battle graphs.
Take into account the intuitive case of designing faculty timetables. Every class may be represented by a node within the graph, and an edge connects two lessons if some college students go to each lessons. Time slots are represented by colours. A correct coloring of the graph – wherein adjoining nodes don’t share the identical coloration – ensures that no scholar is confronted with the predicament of getting to attend two lessons on the identical time. The case of examination scheduling poses an identical drawback, since exams have to be assigned time slots in such a means that no scholar has conflicting examination occasions. Graph coloring can be utilized to resolve this sort of drawback and reduce the variety of time slots wanted general.
Graph coloring may also assist clear up issues of constraint-based scheduling in industrial settings. For instance, product meeting in a automotive manufacturing plant usually includes varied duties, akin to portray, wiring electronics, chassis becoming, and putting in engines. Every activity requires specialised tooling, workstations, and expert employees, and there could also be sure restrictions on activity ordering. Portray mustn’t occur instantly earlier than wiring, since residual paint fumes might harm delicate electronics. Engine set up and chassis becoming could require a number of the identical tools (e.g., lifts or alignment rigs) that’s in brief provide and can’t be used concurrently. To use graph coloring, we will mannequin every activity as a node in a graph, with an edge connecting two nodes if the corresponding duties are in battle (i.e., the duties can’t be scheduled consecutively). Colours characterize distinct time slots or phases of meeting. Correct graph coloring ensures that conflicting duties will not be scheduled back-to-back; this helps optimize the manufacturing workflow, cut back downtime and useful resource bottlenecks, and stop expensive errors.
Clustering and Characteristic Choice
In knowledge mining and machine studying (ML), clustering algorithms group knowledge factors collectively based mostly on shared traits or relationships. Graph coloring gives a pure method to clustering by treating the information as a graph, the place nodes characterize particular person knowledge factors and edges point out some relationship between the respective nodes (e.g., similarity, class membership). Graph coloring permits us to partition the information into impartial units (i.e., teams of nodes that aren’t immediately linked) for efficient detection of clusters; this methodology could also be significantly helpful in social community evaluation, organic knowledge modeling, and suggestion techniques, the place relationships between entities may be fairly complicated. Correct graph coloring helps make sure that every cluster is internally cohesive whereas being distinct from different clusters, offering a clear and interpretable construction for downstream evaluation. readers can take a look at this text and this ebook for a deep dive into graph-theoretic representations of information for characteristic engineering.
Lastly, characteristic choice is a crucial consideration in constructing environment friendly and interpretable ML fashions, particularly within the context of high-dimensional knowledge (e.g., as seen in domains akin to genomics and finance). Coaching a mannequin on many options is computationally costly, and extremely correlated options have a tendency to carry redundant info, which might result in inefficient coaching and overfitting. Graph coloring gives a sublime answer: assemble a graph the place every node represents a characteristic, and edges join pairs of extremely correlated options. A correct coloring of such a graph ensures that no two extremely correlated options are assigned the identical coloration, permitting the collection of one consultant characteristic per coloration. This system reduces dimensionality whereas preserving informational range, resulting in easier fashions that may doubtlessly generalize higher.
The Wrap
Graph coloring, whereas rooted in combinatorial arithmetic, has sensible relevance that extends properly past theoretical puzzles. Ranging from a math contest drawback involving flower petals, we derived common open and closed-form options for the right coloring of cyclical graphs, and checked out how graph coloring may be utilized to a variety of information science issues. The important thing to such sensible purposes lies in sensible drawback framing: if the issue is framed as a graph in the suitable means – with cautious consideration given to the definition of nodes, edges, and coloring constraints – then the answer method could turn into readily obvious. To borrow a quote that’s typically (mis)attributed to Einstein, “if [you] had an hour to resolve an issue, [you should] spend 55 minutes eager about the issue and 5 minutes eager about options.” Finally, as the sphere of information science continues to evolve, strategies akin to graph coloring will seemingly turn into more and more related in each analysis and utilized settings.