The Devil’s Chessboard trick and coloring of the Hamming cube

binarycoloringdiscrete mathematicsgraph theory

For $d \geq 2$, consider the $d$-dimensional Hamming cube $H_d$, i.e. the set of binary sequences $(b_0, b_1, \ldots, b_{d-1})$ with $b_k \in \{0,1\}$ of length $d$. Two such sequences are neighbors if they differ at exactly one position. The Hamming cube can be thought of as a $d$-regular graph with $2^d$ vertices. For what values of $d$ is it possible to color $H_d$ with $d$ colors such that, for any vertex $v \in H_d$, its $d$ neighbors have $d$ different colors. Note that, indeed, such a coloring does not prevent neighbors to share the same color.

It seems possible for $d=2^n$. For example, for $d=2$, one can color:

  • $(0,0)$ and $(1,0)$ in red.
  • $(0,1)$ and $(1,1)$ in blue.

Remark: such a coloring seems to give a solution toe the The Devil's Chessboard problem.

Best Answer

It is only possible for powers of $2$.

Suppose that one of the $d$ colors is red. We know that every vertex has exactly one red neighbor. So if you go through all $2^d$ vertices and, for each vertex $v$, draw an arrow from $v$ to its red neighbor, you will draw $2^d$ arrows. (Edges between two red vertices will have two arrows, one pointing each way.)

However, each red vertex has exactly $d$ arrows pointing to it: one from each of its neighbors! Since there are $2^d$ arrows, there are exactly $\frac{2^d}{d}$ red vertices. So $2^d$ must be divisible by $d$, which means $d$ must be a power of $2$.

The solution to the "Devil's Chessboard puzzle" also gives us a way to color the graph, when $d$ is a power of $2$.

Number the colors $0, 1, 2, \dots, d-1$. For each vertex $\mathbf b = (b_0, b_1, \dots, b_{d-1})$, let $I_{\mathbf b} = \{i : b_i = 1\}$: the set of positions that are $1$ in the vertex. Compute the number $n_{\mathbf b}$ obtained by a bitwise XOR of every element of $I_{\mathbf b}$, and color $\mathbf b$ with the color corresponding to that number.

For every $\mathbf b$, to the neighbor that differs from $b$ in the $i^{\text{th}}$ coordinate has the color corresponding to $n_{\mathbf b} \oplus i$ (where $i$ is bitwise XOR). As $i$ ranges over $0$ to $d-1$, so does $n_{\mathbf b} \oplus i$, so we see all the colors on the neighbors of $\mathbf b$.

(This only works for powers of $2$, because only in that case is $n_{\mathbf b}$ limited to the range $0, 1, \dots, d-1$.)