Algorithm Search⌘K

Proofs: WebGraph compression

These are the human proofs of WebGraph compression, at full length.

Decoding the WebGraph stream recovers every successor list full

This proof shows: correctness, termination.

We use the pseudocode and the format of the page. The input is nn sorted lists S0,…,Sn−1S_0, \ldots, S_{n-1} of distinct integers, a window W≥0W \ge 0 and Lmin⁡≥1L_{\min} \ge 1.

Claim. DECODE(ENCODE(S,W,Lmin⁡)(S, W, L_{\min}), Lmin⁡L_{\min}) returns S0,…,Sn−1S_0, \ldots, S_{n-1}.

Step 1 (the codes). The gamma code is prefix-free: γ(k)\gamma(k) is zz zeros followed by the z+1z + 1 bits of k+1k + 1, which start with 1, so a reader counts the zeros and then knows the length. So reading a field returns the value written, and the reader stops at the end of the field. The map ν\nu is a bijection from the integers to the naturals, with inverse ν−1(k)=k/2\nu^{-1}(k) = k/2 for even kk and −(k+1)/2-(k+1)/2 for odd kk. So every field written as γ(k)\gamma(k) or γ(ν(z))\gamma(\nu(z)) is read back as kk or zz, provided k≥0k \ge 0, which Steps 3 and 4 check.

Step 2 (induction on xx). We show that after the decoder has read the part of list xx, it holds S0,…,SxS_0, \ldots, S_x and stands at the start of the part of list x+1x + 1. The base is the field γ(n)\gamma(n). Assume the claim for all lists before xx. The decoder reads d=∣Sx∣d = |S_x|; if d=0d = 0 the encoder wrote nothing else (line L1), and the list is empty. Otherwise it reads r∗r^* (line L4). If r∗>0r^* > 0, then 1≤r∗≤x1 \le r^* \le x by line L2, and by the hypothesis the decoder holds R=Sx−r∗R = S_{x - r^*}.

Step 3 (copy blocks). Let c0,c1,…,cbc_0, c_1, \ldots, c_b be the runs of the mask of RR, alternating 1s and 0s and starting with 1s. All runs after the first are non-empty, because a run ends only where the next bit differs. The encoder wrote bb, then c0≥0c_0 \ge 0 and cj−1≥0c_j - 1 \ge 0 for 1≤j<b1 \le j < b; it omitted cbc_b. The decoder rebuilds c0,…,cb−1c_0, \ldots, c_{b-1}, walks through RR with them, keeping the elements of the runs of 1s, and gives the rest of RR, which is exactly run cbc_b, the kind that comes next in the alternation. So it obtains the copied set C=Sx∩RC = S_x \cap R.

Step 4 (intervals and residuals). Let E=Sx∖CE = S_x \setminus C, sorted. Line L7 cuts EE into maximal runs of consecutive integers; the runs of length ≥Lmin⁡\ge L_{\min} are the intervals [a1,e1),…,[at,et)[a_1, e_1), \ldots, [a_t, e_t), and the other elements are the residuals y1<⋯<ysy_1 < \cdots < y_s. Since the runs are maximal and EE is sorted, aj+1≥ej+1a_{j+1} \ge e_j + 1: if aj+1=eja_{j+1} = e_j, the integer eje_j would extend run jj. So the fields aj+1−ej−1a_{j+1} - e_j - 1 and λj−Lmin⁡\lambda_j - L_{\min} are ≥0\ge 0, and the decoder rebuilds each interval from the previous end. Since the residuals are distinct and sorted, yj+1−yj−1≥0y_{j+1} - y_j - 1 \ge 0. The decoder knows s=d−∣C∣−∑jλjs = d - |C| - \sum_j \lambda_j, reads ss residuals, the first as x+ν−1(⋅)x + \nu^{-1}(\cdot) and each next one as the previous plus 11 plus the field.

Step 5 (the list). CC, the intervals and the residuals are disjoint and their union is SxS_x, by the definitions of CC and EE and because the runs partition EE. So sorting their union gives SxS_x, and the decoder has read exactly the fields written for xx and stands at the start of the part of x+1x + 1. This completes the induction.

Termination. The encoder runs a loop over xx with inner loops over finite lists. The decoder reads one field per field written, and each read consumes at least one bit, so it stops after reading the whole string. ■\blacksquare

Back to WebGraph compression