Occasionally something diary-
In mid-
The simplest algorithm that does the job is a recursive one. Given a map, pick an uncoloured region, iterate through all the colours for that region which don't already conflict with something else, and for each possibility recurse into the remaining regions, stopping as soon as an answer appears. You can speed this up hugely by choosing, at every stage of the recursion, the currently most constrained region to iterate over next; this prunes the search tree early and often, and although the worst-
But I've never been a fan of algorithms which have a hideous worst case but are OK in practice. So during my initial research for this puzzle, I googled around to see if I could find a four-
The algorithm was a by-
So I mailed one of the authors of the paper and asked if he could clarify some details for me. He replied, in what felt like a rather patronising tone, that he didn't think his algorithm would be much use to me because it was hard to implement.
Well, I'm not scared by that. I'm pretty good at implementing strange algorithms, even algorithms which I've been warned not to try because they're too hard. For example, when I was doing my DipCS, the Algorithms lecturer warned an entire roomful of Cambridge students that they should on no account attempt to implement a B-
So I persisted, and we discussed the details of the algorithm, and gradually –
A basic sketch of the proof of the four-
- Here is a ginormous appendix listing about six hundred small fragments of graphs.
- Given any planar graph (which has had some simple preprocessing done on it), you can guaranteeably find one of those fragments somewhere in it. Proof by exhaustive computer search.
- Given a graph which contains one of those fragments, you can reduce it to a slightly smaller graph, in such a way that if you are then presented with a four-
colouring of the reduced graph you can transform it back into a four- colouring of the original graph. Details of exactly how to do this for each of the 600 fragments are given in the ginormous appendix. - All sufficiently small planar graphs can be four-
coloured, simply by virtue of having at most four vertices. - Hence, essentially by an induction-
like argument, any planar graph can be four- coloured.
The four-
Unfortunately, this also leads to some rather undesirable properties of the algorithm:
- It has quadratic space cost as well as quadratic time. Each recursive step has to construct a slightly reduced version of its input graph, and as best I could tell it pretty much has to construct it in entirely separate memory rather than subtly modifying the original graph data structures. Quadratic space cost is really hideous; I can't think of any algorithm in common use which has it.
- Its linear-
time recursive step has an extremely large time constant. It has to search the graph for one of 600- odd small graph fragments, which is going to take 600 times however long it takes to find one fragment. And before that it has to compute a quantity called ‘charge’ for each vertex of the graph, which is done by another nasty graph- pattern- matching step, and which is vital to knowing whether you've found your fragment or not. Meanwhile, even finding one fragment is painfully slow: you have to essentially iterate over all edges of your input graph and ask ‘Suppose this edge of G corresponded to a given edge of my fragment F; can I then match up the rest of the edges and vertices of F without finding a mismatch?’. - Perhaps worst of all, it isn't sensibly testable. The set of 600 fragments has been proved to be sufficient to guarantee that one can be found in any graph, but hasn't been proved to be necessary. The guy I corresponded with, in fact, was of the opinion that it might easily be that only 20-
50 of them were actually required; he just hadn't managed to prove it. So you end up with 600 special cases in the algorithm code, but you can't construct a set of test inputs which between them exercise more than a small fraction of those special cases. This is a recipe for unreliability.
Once that lot became clear, I abandoned the idea of implementing the algorithm. I still think my original self-
So the current version of Map still uses the simple early-
OTOH my memory of other attempts to prove the theorem suggest to me that as long as your graph doesn't have any vertices which have 5 edges meeting at it then a good algorithm might exist. This stems from the fact it is far easier to prove the 4 colour theorem for all maps without pentagonal countries :).
There exists somewhere in my house a passable (if overly verbose) pop-sci book about the theorem which neatly sets out a) how you can reduce the problem to {2,3,4,5}-agonal countries and b) how {2,3,4}-agonal countries aren't too much of a problem. I believe it is called 'Four colours suffice' or something similar.