Algorithm Search⌘K

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 G=(V,E)G = (V, E) be a simple undirected graph with nn vertices and mm edges. For k=1,…,n+1k = 1, \ldots, n + 1, let RkR_k be the set of vertices removed before round kk of the loop of line L3, and let Gk=G−RkG_k = G - R_k. The degeneracy of GG is dgn(G)=max⁡{δ(H):H⊆G, V(H)≠∅}\mathrm{dgn}(G) = \max \{ \delta(H) : H \subseteq G,\ V(H) \ne \emptyset \}, and 00 when n=0n = 0.

Claim. SMALLEST-LAST(G)(G) stops after nn rounds. The returned order v1,…,vnv_1, \ldots, v_n lists each vertex once, vkv_k has minimum degree in GkG_k, and the returned dd satisfies d=max⁡kdeg⁡Gk(vk)=dgn(G)d = \max_k \deg_{G_k}(v_k) = \mathrm{dgn}(G). Each vkv_k has at most dd neighbors among vk+1,…,vnv_{k+1}, \ldots, v_n. The time is O(n+m)O(n + m).

Invariant. At the start of round kk (before line L4):

(S) Rk={v1,…,vk−1}R_k = \{v_1, \ldots, v_{k-1}\} is the set of marked vertices. For each w∉Rkw \notin R_k, deg⁡[w]=deg⁡Gk(w)\deg[w] = \deg_{G_k}(w) and ww lies in the bucket B[deg⁡[w]]B[\deg[w]], and no bucket holds a marked vertex. Every bucket B[j]B[j] with j<ij < i is empty. Also 0≤i0 \le i, and i≤δ(Gk)i \le \delta(G_k) when GkG_k is not empty.

Initialization. For k=1k = 1, R1=∅R_1 = \emptyset and G1=GG_1 = G. Line L1 sets deg⁡[v]=deg⁡G(v)\deg[v] = \deg_G(v) and puts each vertex in B[deg⁡[v]]B[\deg[v]]. Line L2 sets i=0i = 0, and no bucket has index below 0.

Maintenance. Fix round k≤nk \le n. Then GkG_k has n−k+1≥1n - k + 1 \ge 1 vertices, so some bucket is non-empty, and by (S) each non-empty bucket has index at least ii. Line L4 raises ii to the smallest index jj with B[j]≠∅B[j] \ne \emptyset. The vertices of GkG_k are exactly the bucket contents and each ww is in B[deg⁡Gk(w)]B[\deg_{G_k}(w)], so this smallest jj is δ(Gk)\delta(G_k). Line L5 takes vkv_k from B[δ(Gk)]B[\delta(G_k)], so deg⁡Gk(vk)=δ(Gk)=i\deg_{G_k}(v_k) = \delta(G_k) = i, and line L6 marks it and sets dd to max⁡(d,deg⁡Gk(vk))\max(d, \deg_{G_k}(v_k)).

Now Gk+1=Gk−vkG_{k+1} = G_k - v_k. A vertex ww of Gk+1G_{k+1} has deg⁡Gk+1(w)=deg⁡Gk(w)−1\deg_{G_{k+1}}(w) = \deg_{G_k}(w) - 1 if ww is adjacent to vkv_k, and deg⁡Gk(w)\deg_{G_k}(w) otherwise. Lines L7 and L8 visit exactly the unmarked neighbors of vkv_k, each once because GG is simple, and move each one down by one bucket. So the degree and bucket parts of (S) hold for Gk+1G_{k+1}, and vkv_k is in no bucket. Each degree fell by at most 1, so δ(Gk+1)≥δ(Gk)−1=i−1\delta(G_{k+1}) \ge \delta(G_k) - 1 = i - 1. Every bucket below i−1i - 1 was empty and received no vertex, because a vertex moves from B[j]B[j] to B[j−1]B[j - 1] only for j≥ij \ge i. Line L9 sets ii to max⁡(i−1,0)\max(i - 1, 0), which gives (S) for round k+1k + 1.

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 nn rounds, and v1,…,vnv_1, \ldots, v_n is an order of VV.

The value of dd. By the maintenance step, d=max⁡kδ(Gk)d = \max_k \delta(G_k) at the end.

  • d≤dgn(G)d \le \mathrm{dgn}(G): each GkG_k with k≤nk \le n is a non-empty subgraph of GG.
  • d≥dgn(G)d \ge \mathrm{dgn}(G): let HH be a non-empty subgraph of GG, and let kk be the smallest index with vk∈V(H)v_k \in V(H). Then V(H)⊆V(Gk)V(H) \subseteq V(G_k), so H⊆GkH \subseteq G_k, and δ(H)≤deg⁡H(vk)≤deg⁡Gk(vk)=δ(Gk)≤d\delta(H) \le \deg_H(v_k) \le \deg_{G_k}(v_k) = \delta(G_k) \le d.

Later neighbors. The neighbors of vkv_k among vk+1,…,vnv_{k+1}, \ldots, v_n are its neighbors in GkG_k, and there are deg⁡Gk(vk)≤d\deg_{G_k}(v_k) \le d of them. So greedy coloring in the order vn,…,v1v_n, \ldots, v_1 sees at most dd colored neighbors at each vertex and uses at most d+1d + 1 colors.

Time. Line L1 costs O(n+m)O(n + m). Lines L5, L6 and L9 cost O(1)O(1) per round. Lines L7 and L8 scan the list of vkv_k once in round kk, so ∑vdeg⁡(v)=2m\sum_v \deg(v) = 2m steps of O(1)O(1) in total, with buckets that support insertion and deletion in O(1)O(1). For line L4, let II be the number of increments of ii. The value ii starts at 0, falls by at most 1 in each of the nn rounds, and stays at most n−1n - 1, since a degree in a graph of at most nn vertices is at most n−1n - 1. So I≤(n−1)+nI \le (n - 1) + n, and the tests of line L4 cost O(n+I)=O(n)O(n + I) = O(n). The total is O(n+m)O(n + m). ■\blacksquare

Back to Smallest-last ordering