is coloring an image of a flower that has six petals organized in a circle. She needs 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 shade. Not all 4 colours must be used. What number of methods are there for Rita to paint the flower petals whereas satisfying these constraints? This was the premise of drawback #25 within the 2025 Cayley Contest, and it occurs to be a selected instance of a category of combinatorial information science issues associated to the notion of graph coloring. Within the following sections, we are going to resolve Rita’s concrete drawback, derive its normal open and closed-form options, and take a look at some attention-grabbing sensible functions in trade.
Be aware: All figures and formulation within the following sections have been created by the writer of this text.
A Theoretical Puzzle
To unravel Rita’s drawback, allow us to start by visualizing the flower petals as a cyclical graph consisting of 6 nodes related by edges as proven in Determine 1:
Determine 2 exhibits some legitimate colorings (additionally referred to as correct colorings) of the petals:

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

Thus, we’ve:

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

Determine 5 under exhibits the bottom circumstances for P(n, ok), for a given worth ok:

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

Now, fixing Rita’s drawback quantities to evaluating the recurrence P(n, ok) for n = 6 and ok = 4. For the reason that 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, ok), word that:

Consequently:

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 shortly consider P(n, ok) for bigger enter values:
def num_proper_colorings(n: int, ok: int) -> int:
"""
Iteratively compute the variety of correct colorings of a cycle graph with n nodes and ok colours.
Parameters:
- n (int): Variety of nodes within the cycle graph.
- ok (int): Variety of out there colours.
Returns:
- int: Variety of correct colorings.
"""
if n == 1:
return ok
elif n == 2:
return ok * (ok - 1)
elif n == 3:
return ok * (ok - 1) * (ok - 2)
# Initialize base case num_proper_colorings(3, ok)
num_prev = ok * (ok - 1) * (ok - 2)
for i in vary(4, n + 1):
present = ok * (ok - 1)**(i - 1) - num_prev
num_prev = present
return num_prev
Graph coloring can be operationalized utilizing backtracking, a helpful approach for exploring the answer area of assorted forms of information science issues and incrementally setting up candidate options. This article supplies an intuitive introduction to backtracking, and the next video exhibits how backtracking will be utilized to graph coloring issues specifically:
Closed-Kind Answer
The iterative Python operate proven above has a time complexity of O(n) with respect to variety of nodes n within the cyclical graph. Nonetheless, if we will discover an analytical or closed-form resolution to P(n, ok), we might consider the end result straight; the corresponding Python operate would have a time complexity of simply O(1) and thus signify a considerable time saving as n grows very massive. Time complexity and the deserves of closed-form options are mentioned in additional depth in this article on algorithmic pondering for information scientists.
To discover a simplified closed-form resolution, 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 resolution of a linear algebraic equation f(x) = y is the sum xh + xp of the final resolution xh of its homogeneous counterpart f(x) = 0 and a specific resolution 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 resolution of f(x) = y. Thus, our job is now to:
- Discover a normal resolution xh of the homogeneous equation P(n, ok) + P(n – 1, ok) = 0
- Discover a explicit resolution xp to our recurrence P(n, ok) + P(n – 1, ok) = ok(ok – 1)(n – 1)
- Mix xh and xp to derive the final closed-form resolution of our recurrence
So, allow us to begin by fixing the next homogeneous equation:

Be aware 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 continuing time period C (which we are going to derive shortly) such that:

Subsequent, because the right-hand aspect of the unique recurrence is a a number of of (ok – 1)(n – 1), allow us to strive the next explicit resolution 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:

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 resolution offers us the next closed-form resolution:

We are able to confirm that this certainly offers us the proper resolution for the Cayley contest drawback:

Sensible Functions
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 shade. In essence, graph coloring makes an attempt to partition a graph into impartial units which may be handled uniformly (i.e., all components of a set could also be assigned the identical shade) with out violating adjacency constraints. This kind of drawback framing will be utilized in a variety of knowledge science use circumstances involving constraint-based optimization and useful resource allocation. We take a look at a few of these functions under.
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.
Think about the intuitive case of designing college timetables. Every class will 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 – by which adjoining nodes don’t share the identical shade – 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 the same drawback, since exams have to be assigned time slots in such a method that no scholar has conflicting examination instances. Graph coloring can be utilized to resolve the sort of drawback and decrease the variety of time slots wanted total.
Graph coloring can even assist resolve issues of constraint-based scheduling in industrial settings. For instance, product meeting in a automobile manufacturing plant sometimes includes numerous duties, similar to portray, wiring electronics, chassis becoming, and putting in engines. Every job requires specialised tooling, workstations, and expert employees, and there could also be sure restrictions on job ordering. Portray shouldn’t occur instantly earlier than wiring, since residual paint fumes might harm delicate electronics. Engine set up and chassis becoming might 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 job 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 signify distinct time slots or levels 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 information mining and machine studying (ML), clustering algorithms group information factors collectively primarily based on shared traits or relationships. Graph coloring provides a pure method to clustering by treating the information as a graph, the place nodes signify particular person information 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 straight related) for efficient detection of clusters; this technique could also be notably helpful in social community evaluation, organic information modeling, and suggestion programs, the place relationships between entities will be fairly advanced. Correct graph coloring helps be certain 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 article and this book for a deep dive into graph-theoretic representations of knowledge for characteristic engineering.
Lastly, characteristic choice is a vital consideration in constructing environment friendly and interpretable ML fashions, particularly within the context of high-dimensional information (e.g., as seen in domains similar 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 may result in inefficient coaching and overfitting. Graph coloring provides a chic resolution: 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 shade, permitting the number of one consultant characteristic per shade. This method reduces dimensionality whereas preserving informational variety, resulting in less complicated fashions that may probably generalize higher.
The Wrap
Graph coloring, whereas rooted in combinatorial arithmetic, has sensible relevance that extends effectively past theoretical puzzles. Ranging from a math contest drawback involving flower petals, we derived normal open and closed-form options for the correct coloring of cyclical graphs, and checked out how graph coloring will be utilized to a variety of knowledge science issues. The important thing to such sensible functions lies in sensible drawback framing: if the issue is framed as a graph in the correct method – with cautious consideration given to the definition of nodes, edges, and coloring constraints – then the answer method might change into readily obvious. To borrow a quote that is often (mis)attributed to Einstein, “if [you] had an hour to resolve an issue, [you should] spend 55 minutes desirous about the issue and 5 minutes desirous about options.” In the end, as the sphere of knowledge science continues to evolve, strategies similar to graph coloring will possible change into more and more related in each analysis and utilized settings.