## Wednesday, 24 February 2010

### Polynomials, Coloring Graphs, and Sudoku

Did you ever get half way through a really tough sudoku and begin to wonder if it really has a solution, or finish one and wonder if when you decided that one cell was a five and not a three that if you had picked the other one it STILL would have worked out? The answer, my friend, lies in polynomials.

Recently learned about all this from a nice article you can read for yourself, and maybe if you find my mistakes, drop me a line.

The authors point out that every Sudoku puzzle can be thought of as a graph with 81 vertices (nine rows and nine columns). Now think of the nine numbers in the top row..they would all have to be connected to each other with an edge. They would all have to be connected to each of the cells that are in their same column, and also to the eight others in their sub-square (but they have already been connected to at least four of those, two in their row and two others in their column). By my calculation, that means that each of the 81 vertices would have 8+8+4=20 edges connected to it, for a total of 810 edges.

Now if we associate the number in each cell as a color, a solution would be the same as a properly colored graph (no edge connects two vertices of the same color). An unfinished Sudoku is then a partially colored graph, and solving it is just a matter of finding a way to color the remaining vertices so that no edge connects two vertices of the same color. If it is not possible to do that, there is no solution... and if you can do it more than one way, there is more than one solution.

Now comes the polynomial part. It seems it is "well known" that "The number of ways of coloring a graph G with n colors is well known to be a polynomial in n of degree equal to the number of vertices of G." (Where have I been?). Wait, that means we are looking for a polynomial with degree 81... Ummm.. that may take a little time, so let's look at a simple example.

Suppose we have a simple graph like a triangle, the complete graph of degree three, usually called K3. [A complete graph has each vertex connected to every other vertex with an edge.] It should be clear it can not be properly colored with one or two colors, but with three colors we could do it in six ways (3!). But how many ways could you color if if you had four colors available, or five, or nine, or a complete box of 64 crayola crayons. The answer is pretty easy using the associated polynomial. For K3 the number of ways to color it using n colors is n(n-1)(n-2). So for four colors you could complete the coloring in 24 different ways. You can easily extend the polynomial for a complete graph of t vertices using n colors to get Kt to be n(n-1)(n-2)....(n-t+1).

Ok, so what about one like this? Can you do it in three colors, four, five? If you can write the polynomial for it it should tell you. I admit that I am not sure about how to write some of the pretty simple ones... for instance, if a vertex is joined to two vertices that have n-2 colors possible each, but they are not connected; should that new vertex contribute a (n-3) or an (n-2). Trying to learn as I go along, but mostly by drawing simple ones that I can enumerate all the possible colorings.

Complications spring up when you have a graph that is more complex (and especially if it has 81 vertices), but if you had the polynomial, then you could just evaluate it for n=9 and it would tell you how many solutions there are. The authors did point out some simple theorems that pop out when you make the connection to graphing. For example, any sudoku that gives you only seven of the nine numbers in the "given" must have more than one solution (if it has any). Consider that if you have a solution you could interchange all the cells that have the two missing colors and get another solution. So a puzzle with a unique solution must contain at least eight of the nine numerals. The authors suggest that the number of cells that must be "given" in the problem is an unsolved problem, but they have unique examples with as few as 17, so that would be an upper bound on the solution. The puzzle at the top has eight of the nine digits in it, and exactly 17 cells "given". So does it have a solution? or two? Happy graph coloring children.

Here is a simpler problem, can you write the coloring polynomial for this graph, and find the number of colors for n=3, 4, and 10 colors?