Algorithm Search⌘K

Proofs: Batagelj-Zaversnik algorithm

These are the human proofs of Batagelj-Zaversnik algorithm, at full length.

The Batagelj-Zaversnik algorithm computes the core numbers full

This proof shows: correctness, termination.

Let G=(V,E)G = (V, E) be a simple undirected graph with nn vertices. For a set S⊆VS \subseteq V and a vertex uu, write rS(u)r_S(u) for the number of neighbours of uu in SS. Recall that core(v)\mathrm{core}(v) is the largest kk such that some set S∋vS \ni v has rS(x)≥kr_S(x) \ge k for all x∈Sx \in S.

Termination. Lines L1 to L6 are loops over VV and over 0,…,md0, \ldots, \mathrm{md}. Line L7 runs nn times, and line L9 runs over the finite list Adj[v]\mathrm{Adj}[v]. So the algorithm stops.

In iteration ii of line L7 (counting from 0), call the vertices vert[i],…,vert[n−1]\mathrm{vert}[i], \ldots, \mathrm{vert}[n-1] at its start the remaining vertices, and let RiR_i be their set. We show below that the loop never writes to vert[j]\mathrm{vert}[j] for j≤ij \le i in iteration ii, so the vertex removed in iteration ii is vi=vert[i]v_i = \mathrm{vert}[i], and Ri+1=Ri∖{vi}R_{i+1} = R_i \setminus \{v_i\}. Let DiD_i be the value of deg[vi]\mathrm{deg}[v_i] at line L8, and let D−1=0D_{-1} = 0.

Lemmas 1 and 2 are proved together, by induction on ii.

Lemma 1 (the array). At the start of iteration ii:

  1. vert\mathrm{vert} is a permutation of VV and pos\mathrm{pos} is its inverse;
  2. deg[vert[i]]≤deg[vert[i+1]]≤⋯≤deg[vert[n−1]]\mathrm{deg}[\mathrm{vert}[i]] \le \mathrm{deg}[\mathrm{vert}[i+1]] \le \cdots \le \mathrm{deg}[\mathrm{vert}[n-1]];
  3. for each dd with deg[vert[i]]<d≤md\mathrm{deg}[\mathrm{vert}[i]] < d \le \mathrm{md}, bin[d]\mathrm{bin}[d] is the least index j≥ij \ge i with deg[vert[j]]≥d\mathrm{deg}[\mathrm{vert}[j]] \ge d, or nn if there is none.

Proof. At i=0i = 0: lines L3 and L4 set bin[d]\mathrm{bin}[d] to the number of vertices of degree less than dd. Line L5 places the vertices of degree dd at the indices bin[d],bin[d]+1,…\mathrm{bin}[d], \mathrm{bin}[d] + 1, \ldots, so vert\mathrm{vert} is sorted by degree and pos\mathrm{pos} is its inverse, and after line L5 each bin[d]\mathrm{bin}[d] holds the number of vertices of degree at most dd. Line L6 shifts these values up by one place, from the top down so that no value is overwritten before it is read, so bin[d]\mathrm{bin}[d] is again the number of vertices of degree less than dd, which is the least index of a vertex of degree at least dd. This gives 1 to 3.

Now assume 1 to 3 at the start of iteration ii, and let v=vert[i]v = \mathrm{vert}[i] and D=deg[v]D = \mathrm{deg}[v]. In the iteration, line L13 only changes deg[u]\mathrm{deg}[u] for a neighbour uu with deg[u]>D\mathrm{deg}[u] > D, and lowers it by 1, so it never goes below DD; and u≠vu \ne v since there are no self-loops, so deg[v]=D\mathrm{deg}[v] = D during the whole iteration. We show that one run of lines L11 to L13 keeps 1 and 2, and keeps 3 for all d>Dd > D, with j≥ij \ge i read as j>ij > i.

Let du=deg[u]>Ddu = \mathrm{deg}[u] > D. By 3, pw=bin[du]pw = \mathrm{bin}[du] is the least index ≥i\ge i whose vertex has degree at least dudu. Since deg[v]=D<du\mathrm{deg}[v] = D < du, pw>ipw > i. Since uu has degree dudu and sits at index pu≥ipu \ge i (it is remaining, because each removed vertex vjv_j keeps deg[vj]=Dj≤D\mathrm{deg}[v_j] = D_j \le D by Lemma 2), pw≤pupw \le pu, and by 2 every index from pwpw to pupu holds a vertex of degree exactly dudu. Line L12 swaps the entries at pwpw and pupu and updates pos\mathrm{pos}, so 1 holds, and the degrees along the array are unchanged, so 2 holds. Line L13 lowers the degree at index pwpw to du−1du - 1. All indices from ii to pw−1pw - 1 hold degrees at most du−1du - 1, and all indices after pwpw hold degrees at least dudu, so 2 still holds. For d=dud = du, the least index with degree at least dudu is now pw+1pw + 1 (or nn), and line L13 sets bin[du]=pw+1\mathrm{bin}[du] = pw + 1. For other d>Dd > D, the set of indices with degree at least dd did not change, so bin[d]\mathrm{bin}[d] stays right. No entry at an index ≤i\le i was written, since pw>ipw > i and pu≥pwpu \ge pw.

At the end of the iteration, the next vertex vert[i+1]\mathrm{vert}[i+1] has degree at least DD by 2, so each d>deg[vert[i+1]]d > \mathrm{deg}[\mathrm{vert}[i+1]] has d>Dd > D, and the least index j>ij > i is the least index j≥i+1j \ge i + 1. So 1 to 3 hold at the start of iteration i+1i + 1. □\square

By Lemma 1, part 2, viv_i has the least deg\mathrm{deg} value among the remaining vertices.

Lemma 2 (the degrees). At the start of iteration ii, Di−1≤deg[u]D_{i-1} \le \mathrm{deg}[u] and

deg[u]=max⁡(Di−1,rRi(u))for each u∈Ri,\mathrm{deg}[u] = \max(D_{i-1}, r_{R_i}(u)) \qquad \text{for each } u \in R_i,

and deg[vj]=Dj\mathrm{deg}[v_j] = D_j for each j<ij < i. Moreover Di−1≤DiD_{i-1} \le D_i.

Proof. At i=0i = 0, R0=VR_0 = V, D−1=0D_{-1} = 0 and deg[u]=∣Adj[u]∣=rV(u)\mathrm{deg}[u] = |\mathrm{Adj}[u]| = r_V(u). Assume the claim at the start of iteration ii, and let v=viv = v_i and D=Di=deg[v]D = D_i = \mathrm{deg}[v]. Since vv has the least deg\mathrm{deg} among the remaining vertices and each of them has deg≥Di−1\mathrm{deg} \ge D_{i-1}, we get D≥Di−1D \ge D_{i-1}. Let R′=Ri+1=Ri∖{v}R' = R_{i+1} = R_i \setminus \{v\}. Take u∈R′u \in R'.

  • If uu is a neighbour of vv and deg[u]>D\mathrm{deg}[u] > D: then max⁡(Di−1,rRi(u))>D≥Di−1\max(D_{i-1}, r_{R_i}(u)) > D \ge D_{i-1}, so deg[u]=rRi(u)\mathrm{deg}[u] = r_{R_i}(u). Line L13 sets deg[u]=rRi(u)−1=rR′(u)\mathrm{deg}[u] = r_{R_i}(u) - 1 = r_{R'}(u), which is at least DD. So deg[u]=max⁡(D,rR′(u))\mathrm{deg}[u] = \max(D, r_{R'}(u)).
  • If uu is a neighbour of vv and deg[u]≤D\mathrm{deg}[u] \le D: then deg[u]=D\mathrm{deg}[u] = D by the choice of vv, so rRi(u)≤Dr_{R_i}(u) \le D and rR′(u)<Dr_{R'}(u) < D. The value stays D=max⁡(D,rR′(u))D = \max(D, r_{R'}(u)).
  • If uu is not a neighbour of vv: rR′(u)=rRi(u)r_{R'}(u) = r_{R_i}(u) and deg[u]\mathrm{deg}[u] does not change. If rRi(u)≥Di−1r_{R_i}(u) \ge D_{i-1}, then deg[u]=rR′(u)≥D\mathrm{deg}[u] = r_{R'}(u) \ge D by the choice of vv, which is max⁡(D,rR′(u))\max(D, r_{R'}(u)). Else deg[u]=Di−1≥D≥Di−1\mathrm{deg}[u] = D_{i-1} \ge D \ge D_{i-1}, so D=Di−1=deg[u]>rR′(u)D = D_{i-1} = \mathrm{deg}[u] > r_{R'}(u), and again deg[u]=max⁡(D,rR′(u))\mathrm{deg}[u] = \max(D, r_{R'}(u)).

The value deg[v]=D\mathrm{deg}[v] = D is not changed in iteration ii, as shown in Lemma 1. In later iterations, line L13 only lowers deg[x]\mathrm{deg}[x] when deg[x]>Dj≥D\mathrm{deg}[x] > D_j \ge D for the removed vjv_j, and deg[v]=D\mathrm{deg}[v] = D, so it never touches vv again; the same holds for each earlier vjv_j. This gives the claim at the start of iteration i+1i + 1. □\square

So D0≤D1≤⋯≤Dn−1D_0 \le D_1 \le \cdots \le D_{n-1}, and the returned value for viv_i is DiD_i.

Theorem. For each ii, Di=core(vi)D_i = \mathrm{core}(v_i).

Proof. Lower bound. Let j≤ij \le i be the least index with Dj=DiD_j = D_i. If j=0j = 0, then D0=min⁡urV(u)D_0 = \min_u r_V(u), so every vertex of R0=VR_0 = V has at least DiD_i neighbours in R0R_0. If j>0j > 0, then Dj>Dj−1D_j > D_{j-1}. By Lemma 2, Dj=min⁡u∈Rjmax⁡(Dj−1,rRj(u))D_j = \min_{u \in R_j} \max(D_{j-1}, r_{R_j}(u)), so for each u∈Rju \in R_j, max⁡(Dj−1,rRj(u))≥Dj>Dj−1\max(D_{j-1}, r_{R_j}(u)) \ge D_j > D_{j-1}, which forces rRj(u)≥Djr_{R_j}(u) \ge D_j. In both cases RjR_j is a set in which every vertex has at least DiD_i neighbours, and it contains viv_i since j≤ij \le i. So core(vi)≥Di\mathrm{core}(v_i) \ge D_i.

Upper bound. Let S∋viS \ni v_i be a set with rS(x)≥kr_S(x) \ge k for all x∈Sx \in S. Let vjv_j be the vertex of SS that is removed first, so j≤ij \le i and S⊆RjS \subseteq R_j. Then rRj(vj)≥rS(vj)≥kr_{R_j}(v_j) \ge r_S(v_j) \ge k, and by Lemma 2, Dj=deg[vj]≥rRj(vj)≥kD_j = \mathrm{deg}[v_j] \ge r_{R_j}(v_j) \ge k. Since the DD values do not decrease, Di≥Dj≥kD_i \ge D_j \ge k. Taking k=core(vi)k = \mathrm{core}(v_i) gives Di≥core(vi)D_i \ge \mathrm{core}(v_i).

Line L14 returns deg\mathrm{deg}, and by Lemma 2 at the end, deg[vi]=Di=core(vi)\mathrm{deg}[v_i] = D_i = \mathrm{core}(v_i) for every ii. ■\blacksquare

Back to Batagelj-Zaversnik algorithm