Discrete Mathematics – How Many Ways to Color a Graph?

coloringdiscrete mathematicsgraph theory

Define $D_n$ as a simple undirected graph consisting of $n+2$ vertices, generated by connecting each vertex in a line graph of $n$ vertices to two non-adjacent vertices.

Here is an example of a $D_4$ graph

1

Assume $n,k$ are integers larger or equal to 2.

How many ways are there to color $D_n$ with $k$ colors?

Now, I came with the following solution, I believe there are 2 ways to color $D_n$ with k colors:

  1. Color each of the $n+2$ vertices in a different color
  2. Color the two non-adjacent vertices in the same color, and color the remaining n vertices in different colors.

The number of ways to color $D_n$ with $k$ colors using the first method is $k^{n+2}$, and the number of ways to color $D_n$ with $k$ colors using the second method is $(k – 1) \cdot k^n$.

Thus, the total number of ways to color Dn with $k$ colors is $k^{(n+2)} + (k – 1) \cdot k^n $

But I was wrong, with the case pointed out by Xin Yuan Li in the comments, thus which mistake did I make on my reasoning?

Best Answer

There are two mistakes in the reasoning.


First, if indeed the two cases are "color all vertices different colors" and "color the two 'extra' vertices the same color, and have everything else be different", then the number of ways to color the graph would not be $k^{n+2} + (k-1)k^n$. Instead:

  • When coloring all the vertices different colors, there are $k(k-1)(k-2)\cdots (k-n-1)$ possibilities: each vertex has one fewer color available.
  • When coloring two vertices the same color and never reusing a color again, there are $k(k-1)(k-2)\cdots (k-n)$ possibilities (with one fewer factor).

These add up to $k(k-1)(k-2)\cdots (k-n+1)(k-n)^2$.


Second, the above computes the chromatic polynomial of a different graph: the graph where all vertices in the middle are adjacent to each other. In that case, we really are forced to give them all different colors.

If the vertices in the middle form a path, then the reasoning is different:

  • First, consider the case that the two "extra" vertices have different colors. Choose their colors in $k(k-1)$ ways, then color the path from left to right. The first vertex has $k-2$ choices (it must be different from the two "extra" vertices) and every vertex after that has $k-3$ choices (it must be different from the two "extra" vertices and from the vertex to its left), so we get $k(k-1)(k-2)(k-3)^{n-1}$ solutions.
  • Second, consider the case that the two "extra" vertices have the same color. Choose their color in $k$ ways, then color the path from left to right. The first vertex has $k-1$ choices (it must be different from the two "extra" vertices) and every vertex after that has $k-2$ choices (it must be different from the two "extra" vertices and from the vertex to its left), so we get $k(k-1)(k-2)^{n-1}$ solutions.

Therefore there are $k(k-1)(k-2)(k-3)^{n-1} + k(k-1)(k-2)^{n-1}$ ways to color $D_n$ with $k$ colors.