Fast Modular Subset Sum using Linear Sketching

Kyriakos Axiotis, Arturs Backurs, Ce Jin, Christos Tzamos, Hongxun WuSODA 2018

Abstract

Given $n$ positive integers, the Modular Subset Sum problem asks if a subset adds up to a given target $t$ modulo a given integer $m$. This is a natural generalization of the Subset Sum problem (where $m = \infty$) with ties to additive combinatorics and cryptography. Recently, efficient algorithms have been developed for the non-modular case, running in near-linear pseudo-polynomial time. For the modular case, however, the best known algorithm ran in time $\tilde{O}(m^{5/4})$. In this paper, we present an algorithm running in time $\tilde{O}(m)$, which matches a recent conditional lower bound based on the Strong Exponential Time Hypothesis (SETH). Interestingly, in contrast to most previous results on Subset Sum, our algorithm does not use the Fast Fourier Transform (FFT). Instead, it simulates the "textbook" Dynamic Programming algorithm much faster using ideas from linear sketching, representing one of the first applications of sketching-based techniques to obtain fast algorithms for combinatorial problems in an offline setting.

Introduction

The Subset Sum problem is a fundamental challenge in computer science and complexity theory. Given a set of $n$ integers and a target $t$, the goal is to determine if any subset of these integers sums exactly to $t$. While the problem is NP-complete, it is solvable in pseudo-polynomial time—traditionally $O(nt)$ using Bellman’s classic dynamic programming (DP) approach.

The Modular Subset Sum variant shifts this problem into the domain of modular arithmetic: given a set of integers, does a subset sum to $t \pmod m$? This variation is not merely a theoretical curiosity; it has significant implications for additive combinatorics and cryptographic protocols. Despite its importance, a significant complexity gap existed: while the standard Subset Sum problem had been optimized to near-linear time relative to the target, the modular version remained computationally expensive, with previous state-of-the-art algorithms requiring $\tilde{O}(m^{5/4})$ time.

The Bottleneck of Traditional Dynamic Programming

The standard approach to Subset Sum involves iteratively updating a set of attainable sums. For each new input integer $w_i$, the set of attainable sums $S$ is updated as: $$S_i = S_{i-1} \cup (S_{i-1} + w_i \pmod m)$$

In the modular setting, the set $S$ can contain up to $m$ elements. Processing $n$ elements leads to a total runtime of $O(nm)$. To improve upon this, researchers previously turned to the Fast Fourier Transform (FFT), treating the problem as a form of polynomial multiplication. However, FFT-based methods have limitations in handling the modular structure efficiently, leaving the $\tilde{O}(m)$ bound elusive.

Algorithmic Innovation: Linear Sketching

This paper introduces a breakthrough by moving away from FFT and instead leveraging linear sketching. The authors propose a "constructive" simulation of Bellman’s DP that focuses exclusively on identifying newly attainable sums at each step. By treating the sets of sums as characteristic vectors, the algorithm uses sketching to pinpoint indices where the current set $S$ and the shifted set $(S + w_i)$ differ.

Key Technical Components

  1. Linear Sketching: Traditionally used in streaming data contexts, linear sketching allows the algorithm to maintain "sketches" (inner products with random-looking vectors). These sketches enable the algorithm to detect differences between sets without scanning all $m$ possible values.
  2. Shift-Friendly Hash Families: To make sketching viable for the modular shift operation, the authors utilize a specific family of hash functions: $r = \mathbb{1}_{\{i : ai+b \pmod m \in [0,c]\}}$. This family is "shift-friendly," meaning the sketch of a shifted set $(S + w)$ can be computed efficiently from the sketch of the original set $S$.
  3. Augmented Data Structures: The algorithm employs a Binary Search Tree (BST) augmented to support range queries and updates in $O(\log m)$ time. This allows for the efficient maintenance and querying of sketches as the set of attainable sums evolves.

Results and Complexity

The primary result is an algorithm that solves the Modular Subset Sum problem for all targets $t \in \mathbb{Z}_m$ in $\tilde{O}(m)$ time with high probability. This is a significant theoretical milestone for several reasons:

  • Optimality: The $\tilde{O}(m)$ runtime matches the conditional lower bound based on the Strong Exponential Time Hypothesis (SETH). This suggests that, barring a major upheaval in complexity theory, no significantly faster algorithm is possible.
  • Sketching Beyond Streaming: This work demonstrates that linear sketching is a powerful tool for offline combinatorial problems, not just streaming or dimensionality reduction.
  • Generalization: The technique extends to $d$-dimensional versions of the problem, maintaining a runtime of $\tilde{O}(m^d)$.
  • Non-Modular Implications: By setting the modulus $m$ to be larger than the total sum of all elements, the algorithm provides a new $\tilde{O}(\sum w_i)$ solution for the standard Subset Sum problem that avoids the use of FFT entirely.

Conclusion and Future Work

By replacing FFT with linear sketching, the authors have closed the complexity gap for the Modular Subset Sum problem. The algorithm is not only theoretically optimal but also provides an "online" advantage, as it can output newly attainable sums immediately as each new number is processed.

Future research directions include the search for a deterministic version of this near-linear algorithm, as the current iteration relies on randomization to succeed with high probability. Additionally, the authors pose the question of whether these sketching techniques can solve the non-modular Subset Sum in $O(n + M)$ time, where $M$ is the largest element in the set—a target that remains one of the most intriguing open questions in the field.

Summary updated

BibTeX
@inproceedings{axiotis2018fast,
  author = {Kyriakos Axiotis and Arturs Backurs and Ce Jin and Christos Tzamos and Hongxun Wu},
  title = {{Fast Modular Subset Sum using Linear Sketching}},
  booktitle = {SODA},
  year = {2018},
  url = {https://openreview.net/forum?id=TlBhxtRGgW},
}
Figure