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 , let be the numbers of the arcs, let be fixed, and write and , so . The structure stores and a bit vector high of length with 1s exactly at the positions .
Claim 1 (the layout). The positions are distinct and , and the number of 0s before is .
Proof. Since , , so . The positions before hold the 1s , which are in number, and zeros. Also , which is inside the vector.
Claim 2 (ACCESS). By Claim 1, , so line L1 returns .
Claim 3 (RANK). For , RANK returns .
Proof. Let and . By Claim 1, the 1s with exactly zeros before them are the elements with ; so the elements with are exactly the 1s before the -th zero (counted from 1), that is, before position , or when . The vector has zeros, so this select exists. Before there are positions, of them zeros, so line L4 sets .
The elements with are the 1s in the run that starts at , in increasing order of , hence of . An element with is below , one with is not, and one with is below if and only if . Lines L5 and L6 keep the invariant " is the index of the element at position , and all elements before it are below ": each step passes an element of the bucket with . The loop stops at the first 0, the end of the bucket, or at the first element of the bucket with ; all later elements of the bucket have larger low bits and are not below . So line L7 returns . The loop runs at most the size of the bucket.
Claim 4 (ADJACENT). Let and = RANK. If then , since exactly elements are smaller, and line L10 returns true. If , then either , or is the smallest element at least , and line L10 returns false.
Claim 5 (DEGREE and NEIGHBOR). The arcs out of are the with , so their numbers are exactly the elements of in . Their count is RANK − RANK, which is line L11. They are for = RANK, in increasing order of , so line L12 returns the -th smallest out-neighbour .
Space. Let , so , and write . Then , and the fields use bits. On the function is convex and equals 1 at both ends, so it is at most 1, and the total is at most bits.