Proofs: Greedy coloring
These are the human proofs of Greedy coloring, at full length.
Greedy coloring returns a proper coloring with at most Δ + 1 colors full
This proof shows: correctness, termination.
Let be a simple undirected graph and an order of . For a vertex , let be the set of its earlier neighbors, and . The array has the indices to and starts with a value that is not a vertex.
Claim. GREEDY-COLORING stops. The returned satisfies for each , and for each edge .
Invariant. At the start of iteration of the loop of line L2:
(G) for each , for each , and no edge joins two vertices with and .
Initialization. For , line L1 set all colors to 0, and there is no pair with .
Maintenance. Fix iteration and . By (G), the neighbors of with are exactly the vertices of . Line L4 writes the stamp at the index for each of them. No other entry holds the stamp : an entry gets a stamp only in line L4, and the iterations before wrote other vertices as stamps, because each vertex appears once in . So after line L4,
The set has at most elements. So among the values , at least one is not in . As , these values are valid indices. The loop of line L6 starts at , adds 1 in each step, and stops at the first . So it stops after at most tests, with and . Line L7 sets .
Now has a color of at least 1, and the vertices are still at 0. A new edge between two colored vertices is an edge with , and while , so . Edges between earlier vertices keep their colors, which differ by (G). So (G) holds at the start of iteration .
Termination. The loop of line L2 runs times, and each loop of line L6 runs at most times, as shown. When the loop of line L2 ends, (G) with says that each vertex has a color of at least 1 and that each edge joins two vertices of different colors. The bound was shown in the maintenance step, and .