Proofs: Smallest-last ordering
These are the human proofs of Smallest-last ordering, at full length.
Smallest-last ordering computes the degeneracy in linear time full
This proof shows: correctness, termination.
Let be a simple undirected graph with vertices and edges. For , let be the set of vertices removed before round of the loop of line L3, and let . The degeneracy of is , and when .
Claim. SMALLEST-LAST stops after rounds. The returned order lists each vertex once, has minimum degree in , and the returned satisfies . Each has at most neighbors among . The time is .
Invariant. At the start of round (before line L4):
(S) is the set of marked vertices. For each , and lies in the bucket , and no bucket holds a marked vertex. Every bucket with is empty. Also , and when is not empty.
Initialization. For , and . Line L1 sets and puts each vertex in . Line L2 sets , and no bucket has index below 0.
Maintenance. Fix round . Then has vertices, so some bucket is non-empty, and by (S) each non-empty bucket has index at least . Line L4 raises to the smallest index with . The vertices of are exactly the bucket contents and each is in , so this smallest is . Line L5 takes from , so , and line L6 marks it and sets to .
Now . A vertex of has if is adjacent to , and otherwise. Lines L7 and L8 visit exactly the unmarked neighbors of , each once because is simple, and move each one down by one bucket. So the degree and bucket parts of (S) hold for , and is in no bucket. Each degree fell by at most 1, so . Every bucket below was empty and received no vertex, because a vertex moves from to only for . Line L9 sets to , which gives (S) for round .
Termination. Each round marks one new vertex, and the loop of line L4 stops because a non-empty bucket exists. So the algorithm stops after rounds, and is an order of .
The value of . By the maintenance step, at the end.
- : each with is a non-empty subgraph of .
- : let be a non-empty subgraph of , and let be the smallest index with . Then , so , and .
Later neighbors. The neighbors of among are its neighbors in , and there are of them. So greedy coloring in the order sees at most colored neighbors at each vertex and uses at most colors.
Time. Line L1 costs . Lines L5, L6 and L9 cost per round. Lines L7 and L8 scan the list of once in round , so steps of in total, with buckets that support insertion and deletion in . For line L4, let be the number of increments of . The value starts at 0, falls by at most 1 in each of the rounds, and stays at most , since a degree in a graph of at most vertices is at most . So , and the tests of line L4 cost . The total is .