Abstract 1 Introduction 2 Preliminaries 3 Preprocessed 3SUM for Unknown 𝑪 4 Discussion and Future Work References

Preprocessed 3SUM for Unknown Universes with Subquadratic Space

Yael Kirkpatrick ORCID Massachusetts Institute of Technology, Cambridge, MA, USA    John Kuszmaul ORCID Massachusetts Institute of Technology, Cambridge, MA, USA    Surya Mathialagan ORCID NTT Research, Sunnyvale, CA, USA    Virginia Vassilevska Williams ORCID Massachusetts Institute of Technology, Cambridge, MA, USA
Abstract

We consider the classic 𝟥𝖲𝖴𝖬 problem: given sets of integers A,B,C, determine whether there is a tuple (a,b,c)A×B×C satisfying a+b=c. The 𝟥𝖲𝖴𝖬 Hypothesis, central in fine-grained complexity, states that there does not exist a truly subquadratic time 𝟥𝖲𝖴𝖬 algorithm. Given this long-standing barrier, recent work over the past decade has explored 𝟥𝖲𝖴𝖬 from a data structural perspective. Specifically, in the 𝟥𝖲𝖴𝖬 in preprocessed universes regime, we are tasked with preprocessing sets A,B of size n, to create a space-efficient data structure that can quickly answer queries, each of which is a 𝟥𝖲𝖴𝖬 problem of the form A,B,C, where AA and BB. A series of results have achieved O~(n2) preprocessing time, O~(n2) space, and query time improving progressively from O~(n1.9) [7] to O~(n11/6) [8] to O~(n1.5) [22]. Given these series of works improving query time, a natural open question has emerged: can one achieve both truly subquadratic space and truly subquadratic query time for 𝟥𝖲𝖴𝖬 in preprocessed universes?

We resolve this question affirmatively, presenting a tradeoff curve between query and space complexity. Specifically, we present a simple randomized algorithm achieving O~(n1.5+ε) query time and O~(n22ε/3) space complexity. Furthermore, our algorithm has O~(n2) preprocessing time, matching past work. Notably, quadratic preprocessing is likely necessary for our tradeoff as either the preprocessing or the query time must be at least n2o(1) under the 𝟥𝖲𝖴𝖬 Hypothesis.

Keywords and phrases:
Graph Algorithms, Diameter, Distance Oracle, Approximation Algorithm
Category:
Track A: Algorithms, Complexity and Games
Funding:
Yael Kirkpatrick: Supported by NSF Grant No 2141064.
John Kuszmaul: Supported in part by an MIT Akamai Presidential Fellowship.
Surya Mathialagan: Supported in part by NSF CNS-2154149, a Simons Investigator Award, and Jane Street.
Virginia Vassilevska Williams: Supported by NSF Grant CCF-2330048, BSF Grant 2024233 and a Simons Investigator Award.
Copyright and License:
[Uncaptioned image] © Yael Kirkpatrick, John Kuszmaul, Surya Mathialagan, and Virginia Vassilevska
Williams; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Data structures design and analysis
Related Version:
Full Version: https://arxiv.org/abs/2602.11363
Editors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele Puppis

1 Introduction

One of the central problems in fine-grained complexity is 𝟥𝖲𝖴𝖬: Given three sets of n integers, A,B,C, are there aA,bB,cC so that a+b=c? A classic algorithm solves 𝟥𝖲𝖴𝖬 in O(n2) time. The fastest known algorithm by Baran, Demaine, Pǎtraşcu [3] runs in n2poly(loglogn)/log2n time in the word-RAM model. Chan [6] obtained the same running time in the real-RAM model. The 𝟥𝖲𝖴𝖬 Hypothesis from fine-grained complexity postulates that there is no O(n2ε) time algorithm for 𝟥𝖲𝖴𝖬 for any ε>0. Given this algorithmic barrier, much research has gone into understanding settings in which 𝟥𝖲𝖴𝖬 admits faster algorithms (see e.g., [7, 21, 16, 23, 17, 8, 22]).

In this paper we consider the 𝟥𝖲𝖴𝖬 problem in preprocessed universes, a variant of which was first discussed by Bansal and Williams [2] and attributed to Avrim Blum.

The problem has two variants:

  • 𝟥𝖲𝖴𝖬 in preprocessed universes with known C: Given three sets of n integers A,B,C, preprocess them, so that on any query AA,BB,CC, one can solve 𝟥𝖲𝖴𝖬 on A,B,C fast.

  • 𝟥𝖲𝖴𝖬 in preprocessed universes with unknown C: Given two sets of n integers A,B, preprocess them, so that on any query AA,BB and set of n integers C, one can solve 𝟥𝖲𝖴𝖬 on A,B,C fast.

For both variants there are three natural parameters to optimize: (1) the preprocessing time, (2) the space used after preprocessing, (3) the query time.

Note that under the 𝟥𝖲𝖴𝖬 Hypothesis, either the preprocessing time or the query time must be n2o(1). Hence all prior work has focused on optimizing the query time and space usage, given that the preprocessing time is essentially quadratic. A summary of the prior work is given in Table 1.

Table 1: All running times above include polylogarithmic factors, so they should be thought of as enclosed in O~().
Reference Query Space Unknown C
[7] n13/7 n13/7 NO
[8] n1.891 n1.891 NO
[22] n1.5 n1.5 NO
[7] n1.9 n2 YES
[8] n11/6 n2 YES
[22] n1.5 n2 YES
This work
ε[0,1/2] n1.5+ε n22ε/3 YES

For the known C case, Chan and Lewenstein [7] showed that after O~(n2) preprocessing time111O~ suppresses polylog(n) factors., the 𝟥𝖲𝖴𝖬 queries can be performed in truly subquadratic time of O~(n13/7), while the space usage is also subquadratic, namely O~(n13/7). Fischer [13] extended this to the real RAM model. Chan, Vassilevska Williams and Xu [8] improved the query time and space usage to O(n1.891). With quadratic space usage they also obtained improved query time of O~(n11/6), and this algorithm also worked for the unknown C case for which [7] had achieved O~(n1.9) query time and quadratic space.

More recently, with a much simpler algorithm, Kasliwal, Polak and Sharma [22] drastically improved the query running time and space usage to O(n1.5logn) for the known C case, while keeping the preprocessing time quadratic. For the unknown C case, their approach achieves the same query time but uses quadratic space.

Notably, all known quadratic preprocessing and subquadratic query time algorithms for 𝟥𝖲𝖴𝖬 in preprocessed universes in the case of unknown C use quadratic space. This naturally raises the following question.

Can one achieve essentially quadratic preprocessing time and truly subquadratic space and query time for 𝟥𝖲𝖴𝖬 in preprocessed universes with unknown C?

More generally, we are interested in the trade-off between space usage and query time for the problem. Our main result is as follows:

Theorem 1.

For any ε[0,1/2], there exists a randomized algorithm that preprocesses 2 sets of n integers A,B[U] with U=poly(n), in O~(n2) time using O~(n22ε/3) space, such that upon a query AA,BB and a set of O(n) integers C, it solves 𝟥𝖲𝖴𝖬 on A,B,C in O~(n1.5+ε) time with high probability222With probability 11/poly(n)..

We note that the query time of our algorithm is only guaranteed against an oblivious adversary. While not stated explicitly, this is the case for past works on preprocessed 𝟥𝖲𝖴𝖬 as well.

1.1 Technical Overview

In this paper we combine the techniques of two previously best known results in the field of preprocessed 𝟥𝖲𝖴𝖬 to achieve the first algorithm for preprocessed 𝟥𝖲𝖴𝖬 with unknown C using subquadratic space.

1.2 Prior work on Preprocessed 3SUM

First we consider the recent result of Kasliwal, Polak and Sharma [22], where in the case where C is known at preprocessing, the authors obtain an algorithm with query time O~(n1.5) and O~(n1.5) space. This algorithm is achieved by sampling a random prime p and computing the set of triples a,b,cA×B×C that are not a 𝟥𝖲𝖴𝖬 solution, a+bc, but mod p would look like one, i.e., a+bpc. Such a triple is considered a false positive and the number of false positives is bounded by O(n3p).

Given the subsets A,B,C at query time, the algorithm computes A+B mod p in O(plogp) time using the fast Fourier transform (FFT) - for every cC it computes the number of pairs (a,b)A×B such that a+bpc. It then goes over all stored false positives and for each false positive in A×B×C, subtracts one from the computed number of pairs in A×B that sum to the specified value of c mod p. This leaves us with the number of pairs that truly sum up to c. The algorithm runs in time O~(p+n3p), and so taking p=O(n1.5) gives the desired query time and space.

In the case where C is unknown at preprocessing, the authors use a similar approach of FFT and ruling out false positives. However, in this case, the algorithm stores a data structure that essentially saves the entire sumset A+B, which we will have to avoid in order to achieve subquadratic space.

1.3 Prior work on 3SUM-indexing

The second result we consider is the concurrent works of Golovnev, Guo, Horel, Park and Vaikuntanathan [17] and Kopelowitz and Porat [23], where the authors construct an algorithm for the closely related problem of 𝟥𝖲𝖴𝖬-indexing. In this variant of the problem, we are given the sets A and B to preprocess, and at query time we receive a value c and are asked if there exists a pair aA,bB that sums to it. The question in this case regards the optimal tradeoff between query time and space. The key difference between 𝟥𝖲𝖴𝖬 indexing and preprocessed 𝟥𝖲𝖴𝖬 with unknown C is that for the former, the query is about any pair of numbers in A×B, whereas in the latter, the query asks to find a 𝟥𝖲𝖴𝖬 solution within a specific subset of A and B. Thus, 𝟥𝖲𝖴𝖬-indexing cannot directly solve preprocessed 𝟥𝖲𝖴𝖬 with unknown C and some additional tools are needed in order to apply 𝟥𝖲𝖴𝖬 indexing techniques to the problem of preprocessed 𝟥𝖲𝖴𝖬.

To solve the 𝟥𝖲𝖴𝖬 indexing problem, Golovnev et al. [17] use a hashing argument combined with the cryptographic tool of Fiat-Naor function inversion [12]. This well known result gives a query-time/space tradeoff for the data structures problem of inverting a function, and has found recent algorithmic applications in areas including approximate nearest neighbor search [24], colinearity testing [1], and string indexing methods [5, 4]. Golovnev et al. consider the function f:[|A|]×[|B|]A+B defined by f(i,j)=ai+bj(modp). Inverting this function is equivalent to finding a pair in A×B that sums to a given value (modulus p). However, Fiat-Naor function inversion on its own is insufficient for our problem, as it does not allow for restriction of the sources when multiple candidates exist, which we would need in the case when multiple pairs sum up to a given value but some of them are not in A×B. Thus, this technique cannot be directly applied to the more general problem of preprocessed 𝟥𝖲𝖴𝖬.

1.4 Our techniques

To combine these techniques, we treat the values in the set A+B differently based on their multiplicity, i.e., the number of pairs in A,B that sum to each value. We call a value c a heavy hitter if it has multiplicity at least nδ and denote by C~ the set of all heavy hitters. Note that since every value in C~ has more than nδ different pairs that sum to it, we can bound the size of the set by |C~|=O(n2δ). To handle the heavy hitters, we apply the techniques of [22] and precompute the false positives mod p in A×B×C~. Using a standard argument we can show that the number of such false positives can be bounded by O(n4δp).

Next, we handle the non-heavy hitters. We divide our input set A into =O~(nδ) parts A1,,A. By doing this multiple times, we can guarantee that with high probability, for every value cA+B with multiplicity <nδ, in at least one of the instances there are no two pairs (a1,b1),(a2,b2)A×B that sum to c and fall into the same part in the partition, i.e., no i satisfies a1,a2Ai. We now preprocess a Fiat-Naor inversion on each Ai×B independently, adjusting the function f(a,b)=a+b slightly so that we can use a version of Fiat-Naor with a better time/space tradeoff than the general case used in [17].

Given the sets A,B,C at query time, we compute A+B mod p using FFT. Now, for any heavy hitter cCC~, we rule out the false positives in A×B that sum to c mod p and are left with the number of pairs that sum to c exactly. For every non-heavy hitter cCC~, we query each Fiat-Naor instance to find a pair (a,b)Ai×B that sums to c if such a pair exists. We then check if (a,b)A×B and if so return the triple a,b,c. Since each pair that sums to c falls in a distinct Fiat-Naor instance, this process will scan all such pairs and find one in A×B if one exists.

The space requirements of our algorithm are dominated by the O~(nδ) instances of Fiat-Naor function inversion data structures and the set of O(n4δp) false positives for heavy hitters. By balancing the values of δ,p we obtain a tradeoff between query time and space, achieving subquadratic space for any query time greater than n1.5+Ω(1).

2 Preliminaries

Let [n]{1,2,,n}. Denote by log the base-2 logarithm and by ln the natural log.

Given two sets of numbers A,B we define their sumset as A+B={a+b:aA,bB}. We define the multiplicity of an element cA+B as the number of pairs in A×B that sum up to it: mult(c)|{(a,b)A×B:a+b=c}|. We denote by p equivalence of integers modulo p. We assume the elements of A,B,C (and the sumset A+B) are bounded by nα=poly(n) for some α=O(1), and thus the elements fit into a constant number of machine words. By shifting the values by a constant we can also assume they are all positive.

2.1 Inequalities

We first recall the following inequalities.

Lemma 2 (Markov’s Inequality).

Let X be a non-negative random variable and a0, then

𝐏𝐫[Xa𝔼[X]]1a.
Theorem 3 (Chernoff bound).

Let X=i=1nXi, where each Xi is an independent Bernoulli variable where Xi=1 with probability pi. Let μ=𝔼[X]. Then, for all δ>0,

𝐏𝐫[X(1+δ)μ]eδ2μδ+2.
Lemma 4 (Bernoulli’s Inequality).

For y[0,1) and x1, we have that

(1y)x1xy.

2.2 Preprocessed 3SUM Techniques

We present two key tools used in preprocessed 𝟥𝖲𝖴𝖬 below as lemmas. Attributed to folklore, these lemmas were presented explicitly in [22].

2.3 Computing sumsets mod 𝒑 via FFT

Lemma 5 ([22, Lemma 2.1]).

Given sets A,B of at most n integers, and a positive integer p, we can compute the multiset HA+B(modp) in time O(n+plogp).

We briefly note that computing the multiset of A+B mod p can be reduced to polynomial multiplication of two degree p polynomials, which can be quickly computed via FFT (see [22] for a detailed proof). Given the ease of sumset computation for a small modulus, a natural obstacle that arises in preprocessed 𝟥𝖲𝖴𝖬 is the occurrence of false positives, i.e., triplets of the form (a,b,c)A×B×C such that a+bpc but a+bc. The following lemma bounds the number of such false positives.

2.4 Bounding false positives mod 𝒑

Lemma 6 ([22, Lemma 2.2]).

Let A,B,C[U] be sets of integers bounded by U such that (a,b,c)A×B×C, we have a+bc. Let p be a prime sampled uniformly from [R,2R], for some positive integer R. The expected number of false positives is

𝔼[#{(a,b,c)A×B×C:a+bpc}]O(|A||B||C|logUR).

The proof (see [22]) proceeds by a counting argument, with the key observation that only logr(2U) of the primes in the range [r,2r] can divide |a+bc|. We observe by Markov’s inequality that at least 1/2 of the primes in this range must have at most O(|A||B||C|logU/r) false positives.

We note that the set of false positives F{(a,b,c)A×B×C:a+bpca+bc} can be constructed in O(|A||B|+|C|+r+|F|) time (see the preprocessing step under Theorem 3 of [22]). This will be O(n2+|F|) time for the case that |A||B|,|C|,r=O(n2), as we have in Section 3. See [14, Lemma 3.2] for a deterministic variant of Lemma 6.

2.5 3SUM Indexing Techniques

The main technique used for 𝟥𝖲𝖴𝖬 indexing has been function inversion. Function inversion is a widely studied data structures problem in cryptography [12, 18, 9, 19]. The goal is to give an optimal tradeoff curve between time T and space S for a data structure inverting a function f:[N][N] with pre-processing time O~(N). T bounds the number of queries to f as well as the online computation upon a query. Fiat and Naor [12] present a randomized data structure offering a general tradeoff curve of TS3=O~(N3), which was recently improved [18] to TS2max(S,T)=O~(N3) (our algorithm, however, performs function inversion on the regime in which these two curves are equivalent). Below, we describe the more specific tradeoff provided by Fiat-Naor function inversion for functions with bounded in-degree.

2.6 Fiat-Naor Function Inversion [12]

Lemma 7 ([12]).

Given a function f:[N][N], we can construct a data structure, in pre-processing time O~(N), with time/space O~(T) and O~(S) satisfying the tradeoff TS2=N3q(f), where q(f) denotes the probability that f(x)=f(y) for two uniformly sampled x,y[N]. Thus if f has maximum in-degree Δ, i.e. for all y[N], |f1(y)|Δ, then we can achieve a time/space tradeoff of TS2=N2Δ.

We now prove the following corollary, which exactly describes the regime in which our algorithm performs function inversion. The proof utilizes a hashing argument of [17] as well as the more specific Fiat-Naor tradeoff for bounded in-degree functions.

Corollary 8.

We can perform Fiat-Naor function inversion for any function f:U×VW satisfying |W|,|U||V|=O~(n2δ), of O~(1) maximum in-degree, in space S=n2η and query time T=n2η2δ, for any η[δ,2]. The pre-processing time is O~(n2δ).

Proof.

We observe that the domain and co-domain are both of size N=n2δ, and that Δ=O~(1). Thus we can hash the domain and co-domain to [N] via the technique of [17]. We briefly summarize the hashing argument here (see Section 3 of [17] for a full exposition). In short, if we sample a uniformly random prime pi from the interval [n2,6αn2logn], we can argue that there is a constant probability for any fixed element z1A+B in the sumset, that z1 does not collide under pi with any distinct z2A+B, where we say z1 and z2 collide under pi if z1piz2. This follows via a counting argument, as there are at least 2αn2 primes in the range (for sufficiently large n, by the prime number theorem), and at most (n2)logn2nα<n2α/4 of them divide any z2z1 over all z2A+B. Thus, a uniformly random prime p from the aforementioned interval will avoid any collisions between z1A+B and all other z2A+B with constant probability. Thus we can sample logn such primes during pre-processing, and check that every cA+B avoids collisions under some pi. This constraint will guarantee no false negatives are reported, and we avoid false positives by checking 3-sum solutions against the actual original (a,b,c) triplet before reporting. We then maintain a Fiat-Naor data structure(modpi) for each prime pi, at the cost of a logn time/space blow up. (See the proof of Theorem 3.3 in [17] for a detailed accounting that logn primes is sufficient, and see the proof of Lemma 3.2 in [17] for a detailed description of Fiat-Naor function inversion for 𝟥𝖲𝖴𝖬 modulus p.) By applying Lemma 7, we can then achieve time/space tradeoff TS2=O~((n2δ)2) for function inversion, with pre-processing time O~(N)=O~(n2δ). The choices S=n2η and T=n2η2δ satisfy the equation (where η is a free variable).

3 Preprocessed 3SUM for Unknown 𝑪

We can now prove our main result. As noted in the technical overview, our algorithm handles values differently based on their multiplicity. We describe each part of the algorithm separately. See 1

In fact, our algorithm returns for every cC “yes” if there exists a pair a,bA×B that sums to c and “no” otherwise.

3.1 Heavy Hitters

Let δ>0,r>1 be parameters to be set later. We begin by handling the values of A+B with multiplicity greater than nδ. Define the set of heavy hitters as follows.

Definition 9 (Heavy hitters).

C~{cA+B:|{(a,b)A×B:a+b=c}|nδ}.

As every element in C~ has nδ pairs in A×B that sum to it, we can bound the size of the set by |C~|n2δ. We repeat the following algorithm in parallel logn times in both the preprocessing and query phases.

Preprocessing:

To preprocess the heavy hitters, our algorithm first computes and stores the set C~. Next, we randomly sample a prime p from the range [nr,2nr), compute and store the set of false positives in A×B×C~ mod p:

F{(a,b,c)A×B×C~:a+bpca+bc}.

We store the set F as a dictionary indexed by each tuple’s c coordinate, so that given a value c we can find all triples (a,b,c)F in constant time per triple.

We can construct F in time O~(n2+|F|) and using Lemma 6 with R=nr, bound the size of F by O~(n2|C~|p)O~(n4δr). In total, this preprocessing step stores the sets C~ and F, using space O~(n2δ+n4δr).

Query:

Given the sets A,B,C, compute the multiset HA+B mod p, using Lemma 5 in time O~(p)=O~(nr). For every cCC~, query all triples (a,b,c)F. Count the number of triples such that aA,bB. If this number is smaller than H[c], return “yes” for c, otherwise return “no”.

We note that at query time, our algorithm does not read the entire set F, but only the false positives FF such that their c value is in C,

F{(a,b,c)A×B×(C~C):a+bpca+bc}.

For any cC~C, if there exists a pair (a,b)A×B that sums to c, then H[c] will be greater than the number of triples (a,b,c) in F that have c as their third coordinate with (a,b)A×B. This is because H[c] counts all triples (a,b,c) with (a,b)A×B where a+bpc, which includes any triples in F with first two coordinates from A×B and third coordinate c as well as at least one true (non-false-positive) sum (a,b,c). Hence, the algorithm will output “yes” on any such value cC~C.

By Lemma 6, we can bound the size of F by O~(n2|C~C|p)O~(n3r). By Markov’s inequality, our algorithm can run in O~(n3r) time and scan all of F with constant probability and so repeating this logn times will guarantee success with high probability. Thus, the total runtime of this query algorithm is O~(nr+n3r).

3.2 Non-Heavy Hitters

Next we handle the non-heavy hitters. Let η>0 be a parameter to be set later. Define =nδlogn. We repeat the following algorithm in parallel 4logn times in both the preprocessing and query phases.

Preprocessing:

Construct the sets A1,A2,,A by assigning each element of A to one of the sets Ai uniformly at random. We would like to preprocess a Fiat-Naor function inversion instance on each tuple Ai×B. However, we would like to claim that fi:Ai×BAi+B defined by (a,b)a+b has bounded in-degree. To obtain this, compute M=max(A+B) and define:

f(a,b)={a+ba+bC~,aM+ba+bC~.

To be able to compute f, we store M and C~ using expected O~(n2δ) space. As we show in Claim 10, with probability at least 1n6, each fi has in-degree at most O(logn).

Now, for every i[], preprocess a bounded-in-degree Fiat-Naor function inversion data structure Qi on fif|Ai×B using Corollary 8. This uses O~(n2η2δ) query time and O~(n2η) space.

Note that since all values of A,B are positive, f is an injective function on pairs (a,b) such that a+bC~. In total, we store O~(nδ) instances of a Fiat-Naor data structure, as well as |C~| values of the universe [2U]. Thus, this preprocessing step uses expected O~(n2δ+n2η+δ) space.

Query:

Given the sets A,B,C, perform the following query. For every cCC~, query fi1(c) for every i[] using the preprocessed function inversion data structure Qi. If a pair (a,b)Ai×B is returned, check if (a,b)A×B and if so, return “yes” for this c. If no such pair is found for any i, return “no”.

In total, for every cCC~ we perform O~(nδ) calls to query a Fiat-Naor function inversion data structure for a total query time of O~(nnδn2η2δ)=O~(n1+2ηδ).

The following two claims show the correctness of this stage of the algorithm. First we show that the functions fi do in fact have low in-degree, justifying our use of Corollary 8.

Claim 10.

In each repetition, the functions fi have in-degree at most 11lnn with probability at least 1n6.

Proof.

It suffices to argue that for every cC~, the in-degree of fi for c is at most 11lnn with high probability.

Fix one cC~ and one fi. Denote by μ the expected number of pre-images X for fi for c. By applying a Chernoff bound, we have that

𝐏𝐫(X11lnn)𝐏𝐫(X(1+10lnnμ)μ)e100ln2n/μ10lnn/μ+2.

Bounding further, we obtain 𝐏𝐫(X11lnn)e100ln2n10lnn+2μ. For each cC~, note that the expected number μ of pre-images X for fi for c is less than 1. Hence:

𝐏𝐫(X11lnn)e100ln2n10lnn+2e100ln2n12lnn1/n8.

Therefore, taking a union bound over all (at most n2) cC~ and all (at most ) functions fi, we have that with probability at least 1n6, the functions fi all have in-degree at most 11lnn=O(logn). This allows us to use Corollary 8 and preprocess a Fiat-Naor function inversion data structure for functions with logarithmically bounded in-degree.

Next, we show that this process finds every pair that sums to a value cCC~. Thus, if such a pair exists in A×B the algorithm will be able to find it.

Claim 11.

For every (a,b,c) such that a+b=c and cC~, a query to c uncovers (a,b) with probability at least 11n4.

Proof.

First, we consider a single repetition of the algorithm.

Suppose (a,b)Ai×B. There are at most nδ other pairs (a,b) such that a+b=a+b. For each such a,b, the probability that aAi is 1nδlogn. Since there are at most nδ such a, the probability that all of them are not in Ai is at least (11nδlogn)nδ11logn by Bernoulli’s inequality.

Since we repeat this experiment 4logn times, the probability that at least one of the repetitions outputs (a,b) is

1(1logn)4logn11n4.

When given a query A,B,C, if aA,bB,cC then the algorithm will check (a,b) and thus return “yes” with probability 11n4. By a union bound, if any such triple exists, (a,b,c)A×B×C such that a+b=c and cC~, the algorithm will output “yes” with high probability.

3.3 Putting it All Together

Combining the two algorithms above, given two sets A,B we preprocess them to obtain the data structure for the heavy hitters and non-heavy hitters cases. This uses a total space of O~(n2δ+n4δr+n2η+δ).

Upon query, given A,B,C, we perform the two query algorithms described above to handle CC~ and CC~ separately, for a total query time of O~(nr+n3r+n1+2ηδ).

Setting η=12+ε3,r=32+ε,δ=12ε3 we get a query time of O~(n1.5+ε) using space O~(n22ε/3).

The preprocessing time is dominated by constructing C~, in O~(n2) time, constructing F in O~(n2+|F|)=O~(n2) time, and constructing O~(nδ) instances of a Fiat-Naor function inversion data structure each in time O~(n2δ). Thus, in total, our algorithm takes O~(n2) preprocessing time.

4 Discussion and Future Work

We presented the first data structure for preprocessed 𝟥𝖲𝖴𝖬 with unknown C that has truly subquadratic space and query time (and quadratic preprocessing). We’ll discuss some possible extensions.

4.1 What do we get with optimal function inversion?

The only known lower bounds for function inversion [25, 10, 15] give that the space S and query time T must satisfy

STΩ~(N).

While a matching upper bound is only known for random permutations [19], it is conceivable that a construction achieving this bound might be possible for arbitrary functions as no higher lower bounds are known.

Using a hypothetical optimal function inversion data structure achieving ST=N, just by plugging into our construction, we would obtain for every ε[0,1/2], a data structure for preprocessed 𝟥𝖲𝖴𝖬 with unknown C with

space n2ε and query time n1.5+ε.

4.2 What tradeoff is desirable?

A brute-force query algorithm would solve 𝟥𝖲𝖴𝖬 on each query without the need for preprocessing. This would achieve space O(n) (just store A and B) and query time O(n2)333One can also shave off polylog factors as in [3].. Interpolating between this and the space-n2 and query-n1.5 trade-off of [22], one might hope to be able to achieve for every ε[0,1/2],

space n22ε and query time n1.5+ε.

Unfortunately, even with optimal function inversion, our construction doesn’t achieve such a result. Either new ideas are needed, or perhaps there is some limitation to achieving such a tradeoff.

4.3 Possible extensions?

Our approach can be useful for other potential problems with preprocessing, beyond 𝟥𝖲𝖴𝖬. We give 𝟥𝖷𝖮𝖱 as an example.

In the 𝟥𝖷𝖮𝖱 problem, one is given three n-sized sets of binary strings A,B,C{0,1}d. We want to know whether there exist aA,bB,cC such that abc=0. 𝟥𝖷𝖮𝖱 can be solved in O(n2) time deterministically and, with randomness, in expected time O(n2(loglogn)2/log2n) [11]. It is conjectured (e.g., [20]) that n2o(1) time is necessary.

Analogous to 𝟥𝖲𝖴𝖬, we can define the preprocessed 𝟥𝖷𝖮𝖱 with unknown C problem as: Given A,B{0,1}d, preprocess them so that the following query can be supported efficiently: given AA,BB and C{0,1}d, decide if there exist aA,bB,cC such that abc=0.

We can obtain essentially the same trade-off for 𝟥𝖷𝖮𝖱 as for 𝟥𝖲𝖴𝖬 for this preprocessed version, just by simulating some key steps of the 𝟥𝖲𝖴𝖬 algorithm with 𝟥𝖷𝖮𝖱 primitives.

The first primitive we need to simulate is instance reduction with a small number of false positives. For 𝟥𝖲𝖴𝖬 this was, given some p, to efficiently compute A+Bmodp (with multiplicities) and also to pick p so that the number of false positives is small.

While XORing vectors mod a prime is not defined, Jafargholi and Viola [20] provided an analogous tool for 𝟥𝖷𝖮𝖱. They defined linear hash functions that take a vector a{0,1}d to a vector h(a){0,1} for some choice <<d. This is essentially achieved by random linear combinations of the vector components. Because of linearity, if abc=0, we also have h(a)h(b)h(c)=0. Jafargholi and Viola [20] showed that the expected number of false positives is O(n3/2). Thus, effectively, we can think of p:=2.

For 𝟥𝖲𝖴𝖬 we use the FFT to compute A+Bmodp (with multiplicities) in O~(p) time. For 𝟥𝖷𝖮𝖱 one can use the Walsh-Hadamard transform to compute for all c{0,1}logp the number of pairs (a,b)A×B such that c=ab, i.e., the number of 𝟥𝖷𝖮𝖱 solutions that c is part of. The running time is O(plogp) using the fast folklore recursive algorithm to compute the transform on vectors of length logp.

The rest of our algorithm (Fiat-Naor and Walsh-Hadamard instead of FFT) can be simulated for 𝟥𝖷𝖮𝖱 exactly as for 𝟥𝖲𝖴𝖬, and hence we obtain a trade-off of space usage O~(n22ε/3) and query time O~(n1.5+ε) after quadratic time preprocessing, for preprocessed 𝟥𝖷𝖮𝖱 with unknown C.

The approach can be used for other problems, provided the problems admit analogues of instance size reduction (like mod p) with bounded false positives and of the FFT for computing for every c in the range, the number of solutions in the reduced instance that use c.

References

  • [1] Boris Aronov, Esther Ezra, Micha Sharir, and Guy Zigdon. Time and space efficient collinearity indexing. Computational Geometry, 110:101963, 2023. doi:10.1016/J.COMGEO.2022.101963.
  • [2] Nikhil Bansal and Ryan Williams. Regularity lemmas and combinatorial algorithms. Theory Comput., 8(1):69–94, 2012. doi:10.4086/TOC.2012.V008A004.
  • [3] Ilya Baran, Erik D Demaine, and Mihai Pǎtraşcu. Subquadratic algorithms for 3sum. In Workshop on Algorithms and Data Structures, pages 409–421. Springer, 2005.
  • [4] Jackson Bibbens, Levi Borevitz, and Samuel McCauley. Space-efficient text indexing with mismatches using function inversion. arXiv preprint arXiv:2604.01307, 2026. doi:10.48550/arXiv.2604.01307.
  • [5] Philip Bille, Inge Li Gørtz, Moshe Lewenstein, Solon P Pissis, Eva Rotenberg, and Teresa Anna Steiner. Gapped string indexing in subquadratic space and sublinear query time. In 41st International Symposium on Theoretical Aspects of Computer Science, STACS 2024, pages 1–21. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl Publishing, 2024. doi:10.4230/LIPIcs.STACS.2024.16.
  • [6] Timothy M. Chan. More logarithmic-factor speedups for 3sum, (median,+)-convolution, and some geometric 3sum-hard problems. ACM Trans. Algorithms, 16(1), 2019. doi:10.1145/3363541.
  • [7] Timothy M. Chan and Moshe Lewenstein. Clustered integer 3sum via additive combinatorics. In Proceedings of the Forty-Seventh Annual ACM on Symposium on Theory of Computing, STOC 2015, Portland, OR, USA, June 14-17, 2015, pages 31–40. ACM, 2015. doi:10.1145/2746539.2746568.
  • [8] Timothy M. Chan, Virginia Vassilevska Williams, and Yinzhan Xu. Fredman’s trick meets dominance product: Fine-grained complexity of unweighted apsp, 3sum counting, and more. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing, STOC 2023, Orlando, FL, USA, June 20-23, 2023, pages 419–432. ACM, 2023. doi:10.1145/3564246.3585237.
  • [9] Henry Corrigan-Gibbs and Dmitry Kogan. The function-inversion problem: Barriers and opportunities. In Theory of Cryptography Conference, pages 393–421. Springer, 2019. doi:10.1007/978-3-030-36030-6_16.
  • [10] Anindya De, Luca Trevisan, and Madhur Tulsiani. Time space tradeoffs for attacks against one-way functions and prgs. In Advances in Cryptology - CRYPTO 2010, 30th Annual Cryptology Conference, Santa Barbara, CA, USA, August 15-19, 2010. Proceedings, volume 6223 of Lecture Notes in Computer Science, pages 649–665. Springer, 2010. doi:10.1007/978-3-642-14623-7_35.
  • [11] Martin Dietzfelbinger, Philipp Schlag, and Stefan Walzer. A subquadratic algorithm for 3xor. In 43rd International Symposium on Mathematical Foundations of Computer Science, 2018.
  • [12] Amos Fiat and Moni Naor. Rigorous time/space tradeoffs for inverting functions. In Proceedings of the Twenty-Third Annual ACM Symposium on Theory of Computing, STOC ’91, pages 534–541, New York, NY, USA, 1991. Association for Computing Machinery. doi:10.1145/103418.103473.
  • [13] Nick Fischer. Sumsets, 3sum, subset sum: Now for real! In Proceedings of the 2025 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 4520–4546. SIAM, 2025. doi:10.1137/1.9781611978322.155.
  • [14] Nick Fischer, Piotr Kaliciak, and Adam Polak. Deterministic 3SUM-Hardness. In 15th Innovations in Theoretical Computer Science Conference (ITCS 2024), volume 287 of Leibniz International Proceedings in Informatics (LIPIcs), pages 49:1–49:24. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.ITCS.2024.49.
  • [15] Rosario Gennaro, Yael Gertner, Jonathan Katz, and Luca Trevisan. Bounds on the efficiency of generic cryptographic constructions. SIAM J. Comput., 35(1):217–246, 2005. doi:10.1137/S0097539704443276.
  • [16] Isaac Goldstein, Tsvi Kopelowitz, Moshe Lewenstein, and Ely Porat. Conditional lower bounds for space/time tradeoffs. In Algorithms and Data Structures - 15th International Symposium, WADS 2017, St. John’s, NL, Canada, July 31 - August 2, 2017, Proceedings, volume 10389 of Lecture Notes in Computer Science, pages 421–436. Springer, 2017. doi:10.1007/978-3-319-62127-2_36.
  • [17] Alexander Golovnev, Siyao Guo, Thibaut Horel, Sunoo Park, and Vinod Vaikuntanathan. Data structures meet cryptography: 3sum with preprocessing. In Proceedings of the 52nd Annual ACM SIGACT Symposium on Theory of Computing, STOC 2020, pages 294–307, New York, NY, USA, 2020. Association for Computing Machinery. doi:10.1145/3357713.3384342.
  • [18] Alexander Golovnev, Siyao Guo, Spencer Peters, and Noah Stephens-Davidowitz. Revisiting time-space tradeoffs for function inversion. In Annual International Cryptology Conference, pages 453–481. Springer, 2023. doi:10.1007/978-3-031-38545-2_15.
  • [19] M. Hellman. A cryptanalytic time-memory trade-off. IEEE Transactions on Information Theory, 26(4):401–406, 1980. doi:10.1109/TIT.1980.1056220.
  • [20] Zahra Jafargholi and Emanuele Viola. 3sum, 3xor, triangles. Algorithmica, 74(1):326–343, 2016. doi:10.1007/s00453-014-9946-9.
  • [21] Ce Jin and Yinzhan Xu. Removing additive structure in 3sum-based reductions. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing, STOC 2023, Orlando, FL, USA, June 20-23, 2023, pages 405–418. ACM, 2023. doi:10.1145/3564246.3585157.
  • [22] Shashwat Kasliwal, Adam Polak, and Pratyush Sharma. 3sum in preprocessed universes: Faster and simpler. In 2025 Symposium on Simplicity in Algorithms (SOSA), pages 158–165. SIAM, 2025. doi:10.1137/1.9781611978315.12.
  • [23] Tsvi Kopelowitz and Ely Porat. The strong 3sum-indexing conjecture is false. CoRR, abs/1907.11206, 2019. arXiv:1907.11206.
  • [24] Samuel McCauley. Improved Space-Efficient Approximate Nearest Neighbor Search Using Function Inversion. In 32nd Annual European Symposium on Algorithms (ESA 2024), volume 308 of Leibniz International Proceedings in Informatics (LIPIcs), pages 88:1–88:19. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.ESA.2024.88.
  • [25] Andrew Chi-Chih Yao. Coherent functions and program checkers (extended abstract). In Proceedings of the 22nd Annual ACM Symposium on Theory of Computing, May 13-17, 1990, Baltimore, Maryland, USA, pages 84–94. ACM, 1990. doi:10.1145/100216.100226.