Algorithm Search⌘K

Proofs: Succinct graph representation

These are the human proofs of Succinct graph representation, at full length.

The Elias-Fano graph structure answers access, rank, adjacency, degree and neighbour queries correctly full

This proof shows: correctness.

We use the pseudocode of the page. Let N=n2N = n^2, let P={p0<⋯<pm−1}⊆[0,N)P = \{p_0 < \cdots < p_{m-1}\} \subseteq [0, N) be the numbers un+vun + v of the arcs, let l≥0l \ge 0 be fixed, and write hi=⌊pi/2l⌋h_i = \lfloor p_i / 2^l \rfloor and ℓi=pi mod 2l\ell_i = p_i \bmod 2^l, so pi=hi2l+ℓip_i = h_i 2^l + \ell_i. The structure stores low[i]=ℓi\texttt{low}[i] = \ell_i and a bit vector high of length m+⌊N/2l⌋+1m + \lfloor N/2^l \rfloor + 1 with 1s exactly at the positions ci=hi+ic_i = h_i + i.

Claim 1 (the layout). The positions cic_i are distinct and c0<c1<⋯<cm−1c_0 < c_1 < \cdots < c_{m-1}, and the number of 0s before cic_i is hih_i.

Proof. Since pi<pi+1p_i < p_{i+1}, hi≤hi+1h_i \le h_{i+1}, so ci+1=hi+1+i+1>cic_{i+1} = h_{i+1} + i + 1 > c_i. The positions before cic_i hold the 1s c0,…,ci−1c_0, \ldots, c_{i-1}, which are ii in number, and ci−i=hic_i - i = h_i zeros. Also cm−1≤⌊(N−1)/2l⌋+m−1c_{m-1} \le \lfloor (N-1)/2^l \rfloor + m - 1, which is inside the vector. □\square

Claim 2 (ACCESS). By Claim 1, select1(i)=ci\texttt{select1}(i) = c_i, so line L1 returns (ci−i)2l+ℓi=hi2l+ℓi=pi(c_i - i) 2^l + \ell_i = h_i 2^l + \ell_i = p_i. □\square

Claim 3 (RANK). For 0≤x≤N0 \le x \le N, RANK(x)(x) returns ∣{i:pi<x}∣|\{i : p_i < x\}|.

Proof. Let h=⌊x/2l⌋h = \lfloor x / 2^l \rfloor and r=x mod 2lr = x \bmod 2^l. By Claim 1, the 1s with exactly jj zeros before them are the elements with hi=jh_i = j; so the elements with hi<hh_i < h are exactly the 1s before the hh-th zero (counted from 1), that is, before position q=select0(h−1)+1q = \texttt{select0}(h - 1) + 1, or q=0q = 0 when h=0h = 0. The vector has ⌊N/2l⌋+1≥h+1\lfloor N / 2^l \rfloor + 1 \ge h + 1 zeros, so this select exists. Before qq there are qq positions, hh of them zeros, so line L4 sets k=q−h=∣{i:hi<h}∣k = q - h = |\{i : h_i < h\}|.

The elements with hi=hh_i = h are the 1s in the run that starts at qq, in increasing order of ii, hence of ℓi\ell_i. An element with hi<hh_i < h is below xx, one with hi>hh_i > h is not, and one with hi=hh_i = h is below xx if and only if ℓi<r\ell_i < r. Lines L5 and L6 keep the invariant "kk is the index of the element at position qq, and all elements before it are below xx": each step passes an element of the bucket with ℓk<r\ell_k < r. The loop stops at the first 0, the end of the bucket, or at the first element of the bucket with ℓk≥r\ell_k \ge r; all later elements of the bucket have larger low bits and are not below xx. So line L7 returns ∣{i:pi<x}∣|\{i : p_i < x\}|. The loop runs at most the size ss of the bucket. □\square

Claim 4 (ADJACENT). Let p=un+vp = un + v and kk = RANK(p)(p). If p∈Pp \in P then p=pkp = p_k, since exactly kk elements are smaller, and line L10 returns true. If p∉Pp \notin P, then either k=mk = m, or pk>pp_k > p is the smallest element at least pp, and line L10 returns false. □\square

Claim 5 (DEGREE and NEIGHBOR). The arcs out of uu are the (u,v)(u, v) with 0≤v<n0 \le v < n, so their numbers are exactly the elements of PP in [un,un+n)[un, un + n). Their count is RANK(un+n)(un + n) − RANK(un)(un), which is line L11. They are pk,…,pk+d−1p_k, \ldots, p_{k + d - 1} for kk = RANK(un)(un), in increasing order of vv, so line L12 returns the ii-th smallest out-neighbour pk+i−unp_{k+i} - un. □\square

Space. Let t=log⁡2(N/m)t = \log_2(N/m), so l=⌊t⌋l = \lfloor t \rfloor, and write f=t−l∈[0,1)f = t - l \in [0, 1). Then N/2l=m2fN / 2^l = m 2^f, and the fields use ml+m+⌊N/2l⌋+1≤m(t+1+2f−f)+1ml + m + \lfloor N/2^l \rfloor + 1 \le m(t + 1 + 2^f - f) + 1 bits. On [0,1)[0, 1) the function 2f−f2^f - f is convex and equals 1 at both ends, so it is at most 1, and the total is at most m(2+log⁡2(N/m))+1m(2 + \log_2(N/m)) + 1 bits. ■\blacksquare

Back to Succinct graph representation