Proofs: DSATUR
These are the human proofs of DSATUR, at full length.
DSATUR returns a proper coloring and two-colors every bipartite graph full
This proof shows: correctness, termination.
Let be a simple undirected graph with vertices. Call round the -th run of the loop of line L2, and let be the set of uncolored vertices at its start, so .
Claim. DSATUR stops after rounds and returns with for all and for each edge . The color of is at most at the moment it is colored. If is bipartite, for all .
Invariant. At the start of round :
(D) exactly for , and . For each , and . No edge joins two colored vertices of the same color.
Initialization. Line L1 sets every color to 0, every to and to , which is (D) for .
Maintenance. In round , is not empty, so line L3 finds a vertex . The set has at most elements, so one of is not in it, and line L4 stops with and . By (D), differs from the color of every colored neighbor of , so after line L5 no edge joins two colored vertices of the same color. Now . For , the set gains exactly when is a neighbor of ; lines L6 to L8 add to and lower by one for exactly these , once each since is simple. So (D) holds at the start of round . Also .
Termination. Each round colors one vertex of , and line L4 stops after at most tests. After rounds, (D) with says that all vertices are colored with colors at least 1 and the coloring is proper.
Bipartite graphs. Let be bipartite with a bipartition fixed in each connected component. We show by induction on that at the start of round :
(B) at most one connected component is partly colored (it has colored and uncolored vertices); in that component the colored vertices induce a connected subgraph; and every colored vertex has color 1 or 2, with the colors given by the sides of its component (in each component, all colored vertices of one side share one color, and the other side has the other color).
For nothing is colored. Assume (B) at round and let be the vertex chosen at line L3.
Case 1: some component is partly colored. Since is connected and has colored and uncolored vertices, some uncolored has a colored neighbor, so . A vertex in any other component has no colored neighbor, because the other components are fully colored or fully uncolored; so its saturation is 0. Line L3 compares saturation first, so and . All colored neighbors of lie on the side of opposite to , so by (B) they all have one color , and . Line L4 gives the color . If other colored vertices of lie on the side of , then by (B) they have the color other than , which is ; so the colors in still follow the sides. The colored part of stays connected, because has a colored neighbor. So (B) holds after round , with partly colored or now fully colored.
Case 2: no component is partly colored. Then every uncolored vertex has saturation 0, and starts a new component with , so . The colored part of is , which is connected and uses the color 1 on the side of . If , then is fully colored. So (B) holds after round .
In both cases each new color is 1 or 2. So DSATUR colors every bipartite graph with at most 2 colors.