Table of Contents
Fetching ...

3SUM in Preprocessed Universes: Faster and Simpler

Shashwat Kasliwal, Adam Polak, Pratyush Sharma

TL;DR

This work studies 3SUM in preprocessed universes, where preprocessing on three sets of size $n$ enables fast queries on their subsets. It introduces a randomized Las Vegas approach that preprocesses in $O(n^2)$ time and uses FFT plus modular hashing to answer queries in $O(n^{1.5}\log n)$, while also allowing per-$c$ solution reporting and handling unknown $C$ with the same time bound but larger space. Deterministic variants are provided: for known $C$ via a modulus-derandomization technique, and for unknown $C$ with $O(n^2\log n)$ preprocessing and $O(n^{1.5}\log^3 n)$ query time, achieved by partitioning moduli and counting witnesses accordingly. Relative to prior subquadratic results based on additive combinatorics, these methods offer faster and conceptually simpler solutions that rely on FFT and linear hashing rather than deep theorems, with practical implications for fast, preprocessed 3SUM queries.

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.

3SUM in Preprocessed Universes: Faster and Simpler

TL;DR

This work studies 3SUM in preprocessed universes, where preprocessing on three sets of size enables fast queries on their subsets. It introduces a randomized Las Vegas approach that preprocesses in time and uses FFT plus modular hashing to answer queries in , while also allowing per- solution reporting and handling unknown with the same time bound but larger space. Deterministic variants are provided: for known via a modulus-derandomization technique, and for unknown with preprocessing and query time, achieved by partitioning moduli and counting witnesses accordingly. Relative to prior subquadratic results based on additive combinatorics, these methods offer faster and conceptually simpler solutions that rely on FFT and linear hashing rather than deep theorems, with practical implications for fast, preprocessed 3SUM queries.

Abstract

We revisit the 3SUM problem in the \emph{preprocessed universes} setting. We present an algorithm that, given three sets , , of integers, preprocesses them in quadratic time, so that given any subsets , , , it can decide if there exist , , with in time . In contrast to both the first subquadratic -time algorithm by Chan and Lewenstein (STOC 2015) and the current fastest -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 if there is a solution containing it. We also modify the algorithm to still work in the scenario where the set 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.

Paper Structure

This paper contains 23 sections, 6 theorems, 10 equations, 1 table.

Key Result

Lemma 2.1

Given two sets $A$, $B$ of $n$ integers and a positive integer $m$, one can compute in time $O(n + m \log m)$ the multiset $(A + B) \bmod m$, represented as its multiplicity vector $(v_0, v_1, \ldots, v_{m-1}) \in \mathbb{Z}^m$, where for every $i \in [m]$,

Theorems & Definitions (6)

  • Lemma 2.1: Sumset computation using FFT
  • Lemma 2.2: False positives modulo a prime
  • Theorem 3.1
  • Theorem 4.1
  • Theorem 5.1
  • Lemma 5.2: Adapted from FischerK024