Algorithm Search⌘K

Proofs: PPJoin

These are the human proofs of PPJoin, at full length.

PPJoin reports exactly the pairs above the Jaccard threshold full

This proof shows: correctness.

We use the names of the pseudocode on the page. Fix RR, a threshold 0<t≤10 < t \le 1, and the global order ≺\prec. Every set is a sorted list x[1]≺x[2]≺⋯≺x[∣x∣]x[1] \prec x[2] \prec \cdots \prec x[|x|], and the sets are processed in a fixed order in which ∣y∣≤∣x∣|y| \le |x| whenever yy comes before xx. Write

p(x)=∣x∣−⌈t∣x∣⌉+1,q(x)=∣x∣−⌈2t1+t∣x∣⌉+1,α(x,y)=⌈t1+t(∣x∣+∣y∣)⌉p(x) = |x| - \lceil t|x| \rceil + 1, \qquad q(x) = |x| - \left\lceil \tfrac{2t}{1+t}|x| \right\rceil + 1, \qquad \alpha(x, y) = \left\lceil \tfrac{t}{1+t}(|x| + |y|) \right\rceil

for the probing prefix length, the indexing prefix length and the required overlap.

Lemma 1 (overlap form). For nonempty xx and yy, J(x,y)≥tJ(x, y) \ge t if and only if ∣x∩y∣≥α(x,y)|x \cap y| \ge \alpha(x, y).

Proof. Let o=∣x∩y∣o = |x \cap y|, so ∣x∪y∣=∣x∣+∣y∣−o>0|x \cup y| = |x| + |y| - o > 0. Then o/(∣x∣+∣y∣−o)≥to / (|x| + |y| - o) \ge t if and only if o≥t(∣x∣+∣y∣)−too \ge t(|x| + |y|) - to, that is o≥t1+t(∣x∣+∣y∣)o \ge \frac{t}{1+t}(|x| + |y|). Since oo is an integer, this holds if and only if o≥α(x,y)o \ge \alpha(x, y). □\square

Lemma 2 (the index). When the probe of xx starts in line L3, the list I[w]I[w] holds exactly the pairs (y,j)(y, j) such that yy was processed before xx, y[j]=wy[j] = w and j≤q(y)j \le q(y), in the order in which those sets were processed.

Proof. Line L2 starts with an empty index. During the probe of yy, line L11 appends (y,i)(y, i) to I[y[i]]I[y[i]] exactly for the i≤min⁡(p(y),q(y))i \le \min(p(y), q(y)). Since 2t1+t≥t\frac{2t}{1+t} \ge t for t≤1t \le 1, q(y)≤p(y)q(y) \le p(y), so these are the i≤q(y)i \le q(y). Nothing else changes II. The appends during the probe of xx itself come after all reads of the same list in that iteration of line L5, and xx has no repeated element, so xx never meets itself. □\square

Lemma 3 (the counter). During the probe of xx, at the moment line L9 examines the pair (y,j)(y, j) found under w=x[i]w = x[i], if yy is not pruned for xx, then A[y]A[y] equals the number of elements u∈x∩yu \in x \cap y with u≺wu \prec w.

Proof. Let u∈x∩yu \in x \cap y with u≺wu \prec w, at position i′i' of xx and j′j' of yy. Then i′<ii' < i, and since ww is in yy at position jj and u≺wu \prec w, j′<j≤q(y)j' < j \le q(y). So uu is in the probing prefix of xx, and by Lemma 2, (y,j′)(y, j') is in I[u]I[u]. When the loop of line L5 reached i′i', line L7 met (y,j′)(y, j'). The size test gave the same answer as now, since it depends only on ∣x∣|x| and ∣y∣|y|, and it passes now. The pair yy was not pruned then, since pruning is permanent for the probe of xx and yy is not pruned now. So line L9 ran on it, and its test passed, or yy would be pruned. So A[y]A[y] grew by one for uu. Conversely A[y]A[y] grows only in line L9, once per element of xx met in a list entry of yy, and such an element is common to xx and yy and earlier than ww. Each common element gives one entry, since yy has no repeated element. □\square

Lemma 4 (the positional bound). In the situation of Lemma 3, ∣x∩y∣≤A[y]+1+min⁡(∣x∣−i,∣y∣−j)|x \cap y| \le A[y] + 1 + \min(|x| - i, |y| - j).

Proof. Split x∩yx \cap y by the element ww, which is common. The elements before ww number A[y]A[y] by Lemma 3. The element ww counts one. An element after ww is among x[i+1],…,x[∣x∣]x[i+1], \ldots, x[|x|] and among y[j+1],…,y[∣y∣]y[j+1], \ldots, y[|y|], so there are at most min⁡(∣x∣−i,∣y∣−j)\min(|x| - i, |y| - j) of them. □\square

Lemma 5 (the prefixes). Let xx and yy be nonempty with ∣y∣≤∣x∣|y| \le |x| and J(x,y)≥tJ(x, y) \ge t, and let uu be the ≺\prec-least element of x∩yx \cap y, with x[i]=u=y[j]x[i] = u = y[j]. Then ∣y∣≥t∣x∣|y| \ge t|x|, i≤p(x)i \le p(x) and j≤q(y)j \le q(y).

Proof. We have ∣y∣≥∣x∩y∣≥t∣x∪y∣≥t∣x∣|y| \ge |x \cap y| \ge t|x \cup y| \ge t|x|. Let α=α(x,y)\alpha = \alpha(x, y); by Lemma 1, ∣x∩y∣≥α|x \cap y| \ge \alpha. All common elements are at or after uu in xx, so ∣x∣−i+1≥α|x| - i + 1 \ge \alpha, that is i≤∣x∣−α+1i \le |x| - \alpha + 1; in the same way j≤∣y∣−α+1j \le |y| - \alpha + 1. Now ∣y∣≥t∣x∣|y| \ge t|x| gives t1+t(∣x∣+∣y∣)≥t1+t(1+t)∣x∣=t∣x∣\frac{t}{1+t}(|x| + |y|) \ge \frac{t}{1+t}(1+t)|x| = t|x|, so α≥⌈t∣x∣⌉\alpha \ge \lceil t|x| \rceil and i≤p(x)i \le p(x). And ∣x∣≥∣y∣|x| \ge |y| gives t1+t(∣x∣+∣y∣)≥2t1+t∣y∣\frac{t}{1+t}(|x| + |y|) \ge \frac{2t}{1+t}|y|, so α≥⌈2t1+t∣y∣⌉\alpha \ge \lceil \frac{2t}{1+t}|y| \rceil and j≤q(y)j \le q(y). □\square

Theorem. PPJOIN outputs a pair (x,y)(x, y) if and only if xx and yy are distinct nonempty sets of RR with J(x,y)≥tJ(x, y) \ge t, and it outputs each such pair once.

Proof. (Soundness.) Line L13 outputs (x,y)(x, y) only if ∣x∩y∣≥α(x,y)|x \cap y| \ge \alpha(x, y), that is, by Lemma 1, only if J(x,y)≥tJ(x, y) \ge t. An empty set has no prefix, so it never enters II and never probes.

(Uniqueness.) A pair is considered only during the probe of the later of its two sets, by Lemma 2, and line L12 visits each yy once in that probe.

(Completeness.) Let J(x,y)≥tJ(x, y) \ge t, with yy processed before xx, so ∣y∣≤∣x∣|y| \le |x|. Take uu, ii and jj as in Lemma 5. By Lemma 5 and Lemma 2, i≤p(x)i \le p(x), so the loop of line L5 reaches w=uw = u, and (y,j)(y, j) is in I[u]I[u], and the size filter of line L7 passes. We claim that yy is never pruned during the probe of xx. Suppose line L10 prunes yy for the first time, at an element w=x[i′]w = x[i'] with y[j′]=wy[j'] = w. Before that yy was not pruned, so Lemma 4 applies and gives A[y]+1+min⁡(∣x∣−i′,∣y∣−j′)≥∣x∩y∣≥α(x,y)A[y] + 1 + \min(|x| - i', |y| - j') \ge |x \cap y| \ge \alpha(x, y), by Lemma 1. So the test of line L9 passes, a contradiction. At w=uw = u the test passes as well, so A[y]≥1A[y] \ge 1 after it, and line L12 visits yy. Line L13 checks ∣x∩y∣≥α(x,y)|x \cap y| \ge \alpha(x, y), which holds, and outputs the pair. ■\blacksquare

Back to PPJoin