3SUM in Preprocessed Universes: Faster and Simpler

Shashwat Kasliwal,Adam Polak,Pratyush Sharma
2024-11-01
Abstract:We revisit the 3SUM problem in the \emph{preprocessed universes} setting. We present an algorithm that, given three sets $A$, $B$, $C$ of $n$ integers, preprocesses them in quadratic time, so that given any subsets $A' \subseteq A$, $B' \subseteq B$, $C' \subseteq C$, it can decide if there exist $a \in A'$, $b \in B'$, $c \in C'$ with $a+b=c$ in time $O(n^{1.5} \log n)$. In contrast to both the first subquadratic $\tilde{O}(n^{13/7})$-time algorithm by Chan and Lewenstein (STOC 2015) and the current fastest $\tilde{O}(n^{11/6})$-time algorithm by Chan, Vassilevska Williams, and Xu (STOC 2023), which are based on the Balog--Szemerédi--Gowers theorem from additive combinatorics, our algorithm uses only standard 3SUM-related techniques, namely FFT and linear hashing modulo a prime. It is therefore not only faster but also simpler. Just as the two previous algorithms, ours not only decides if there is a single 3SUM solution but it actually determines for each $c \in C'$ if there is a solution containing it. We also modify the algorithm to still work in the scenario where the set $C$ is unknown at the time of preprocessing. Finally, even though the simplest version of our algorithm is randomized, we show how to make it deterministic losing only polylogarithmic factors in the running time.
Data Structures and Algorithms
What problem does this paper attempt to address?
The problem that this paper attempts to solve is the optimization of the 3SUM problem in the preprocessed universes setting. Specifically, given three sets of integers \(A, B, C\), each containing \(n\) integers, the goal is, after preprocessing these sets, for any subsets \(A' \subseteq A\), \(B' \subseteq B\), \(C' \subseteq C\), to be able to quickly determine whether there exist \(a \in A'\), \(b \in B'\), \(c \in C'\) such that \(a + b = c\). ### Main Contributions 1. **Faster Algorithm**: The paper proposes a new algorithm. With a preprocessing time of \(O(n^2)\), the query time can reach \(O(n^{1.5} \log n)\). This is faster than the previous best algorithms, such as \(\tilde{O}(n^{13/7})\) by Chan and Lewenstein [CL15] and \(\tilde{O}(n^{11/6})\) by Chan, Vassilevska Williams, and Xu [CVWX23]. 2. **Simpler Algorithm**: The new algorithm only uses standard 3SUM - related techniques, such as the Fast Fourier Transform (FFT) and linear hashing modulo prime numbers, without relying on complex additive combinatorics tools (such as the Balog - Szemerédi - Gowers theorem). Therefore, this algorithm is not only faster but also simpler and easier to understand. 3. **Handling of the Unknown Set \(C\)**: The paper also proposes an improved version of the algorithm that can work without knowing the set \(C\) during preprocessing and still maintain the same query time of \(O(n^{1.5} \log n)\). 4. **Deterministic Algorithm**: Although the simplest version is randomized, the paper shows how to make the algorithm deterministic by introducing a logarithmic factor. ### Algorithm Overview - **Preprocessing Phase**: - Randomly select a prime number \(p \in [n^{1.5}, 2n^{1.5})\). - Calculate all possible "false positive" triples \(F=\{(a, b, c) \in A\times B\times C : a + b\equiv c\pmod{p} \land a + b\neq c\}\). - **Query Phase**: - Use FFT to calculate \((A' + B')\mod p\). - Create a hash table \(H\) to store the number of solutions for each \(c \in C'\). - Traverse the false - positive set \(F\), subtract the number of false positives, and obtain the final solution. ### Conclusion The paper, by simplifying and optimizing existing methods, provides a faster and simpler solution to handle the variant of the 3SUM problem in the preprocessed universes setting. This progress helps to better understand the complexity of the 3SUM problem and provides new ideas for future research.