Lune

FOCS2023Top-tier venue

Faster Algorithms for Text-to-Pattern Hamming Distances

Timothy M. Chan, Ce Jin, Virginia Vassilevska Williams, Yinzhan Xu

Abstract

We study the classic Text-to-Pattern Hamming Distances problem: given a pattern P of length m and a text T of length n, both over a polynomial-size alphabet, compute the Hamming distance between P and T[i…i+m−1]T[i \ldots i+m-1] for every shift i, under the standard Word-RAM model with Θ(log⁡n)\Theta(\log n)-bit words.•We provide an O(nm)O(n \sqrt{m}) time Las Vegas randomized algorithm for this problem, beating the decades-old O(nmlog⁡m)O(n \sqrt{m \log m}) running time [Abrahamson, SICOMP 1987]. We also obtain a deterministic algorithm, with a slightly higher O(nm(log⁡mlog⁡log⁡m)1/4)O\left(n \sqrt{m}(\log m \log \log m)^{1 / 4}\right) running time. Our randomized algorithm extends to the k-bounded setting, with running time O(n+nkm)O\left(n+\frac{n k}{\sqrt{m}}\right), removing all the extra logarithmic factors from earlier algorithms [Gawrychowski and Uznanski, ICALP 2018; Chan, Golan, Kociumaka, Kopelowitz and Porat, STOC 2020].•For the (1+ε)(1+\varepsilon)-approximate version of Text-to-Pattern Hamming Distances, we give an O~(ε−0.93n)\widetilde{O}\left(\varepsilon^{-0.93} n\right) time Monte Carlo randomized algorithm (where O~\widetilde{O} hides poly-logarithmic factors), beating the previous O~(ε−1n)\widetilde{O}\left(\varepsilon^{-1} n\right) running time [Kopelowitz and Porat, FOCS 2015; Kopelowitz and Porat, SOSA 2018].Our approximation algorithm exploits a connection with 3SUM, and uses a combination of Fredman’s trick, equality matrix product, and random sampling; in particular, we obtain new results on approximate counting versions of 3 SUM and Exact Triangle, which may be of independent interest. Our exact algorithms use a novel combination of hashing, bit-packed FFT, and recursion; in particular, we obtain a faster algorithm for computing the sumset of two integer sets, in the regime when the universe size is close to quadratic in the number of elements. We also prove a fine-grained equivalence between the exact Text-to-Pattern Hamming Distances problem and a range-restricted, counting version of 3 SUM.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

4 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • New Applications of 3SUM-Counting in Fine-Grained Complexity and Pattern Matching cites Faster Matrix Multiplication via Asymmetric Hashing
  • New Applications of 3SUM-Counting in Fine-Grained Complexity and Pattern Matching cites A Fine-Grained Perspective on Approximating Subset Sum and Partition
  • New Applications of 3SUM-Counting in Fine-Grained Complexity and Pattern Matching cites New Bounds for Matrix Multiplication: from Alpha to Omega
  • A Fine-Grained Perspective on Approximating Subset Sum and Partition cites Top-k-convolution and the quest for near-linear output-sensitive subset sum
  • New Bounds for Matrix Multiplication: from Alpha to Omega cites Faster Matrix Multiplication via Asymmetric Hashing
  • Shaving Logs via Large Sieve Inequality: Faster Algorithms for Sparse Convolution and More cites Top-k-convolution and the quest for near-linear output-sensitive subset sum
  • Shaving Logs via Large Sieve Inequality: Faster Algorithms for Sparse Convolution and More cites A Fine-Grained Perspective on Approximating Subset Sum and Partition
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers4

  1. New Applications of 3SUM-Counting in Fine-Grained Complexity and Pattern MatchingNick Fischer, Ce Jin, Yinzhan XuSODA 2025 · 2 citations
  2. Faster two-dimensional pattern matching with k mismatchesJonas Ellert, Pawel Gawrychowski, Adam Górkiewicz, Tatiana StarikovskayaSODA 2025 · 1 citation
  3. Near-Optimal Property Testers for Pattern MatchingCe Jin, Tomasz KociumakaFOCS 2025 · 1 citation
  4. Shaving Logs via Large Sieve Inequality: Faster Algorithms for Sparse Convolution and MoreCe Jin, Yinzhan XuSTOC 2024 · 1 citation

Builds on12

  1. New Bounds for Matrix Multiplication: from Alpha to OmegaVirginia Vassilevska Williams, Yinzhan Xu, Zixuan Xu, Renfei ZhouSODA 2024 · 90 citations
  2. Faster Matrix Multiplication via Asymmetric HashingRan Duan, Hongxun Wu, Renfei ZhouFOCS 2023 · 54 citations
  3. Top-k-convolution and the quest for near-linear output-sensitive subset sumKarl Bringmann, Vasileios NakosSTOC 2020 · 18 citations
  4. A Fine-Grained Perspective on Approximating Subset Sum and PartitionKarl Bringmann, Vasileios NakosSODA 2021 · 14 citations
  5. Elliptic Curve Fast Fourier Transform (ECFFT) Part I: Low-degree Extension in Time O(n log n) over all Finite FieldsEli Ben-Sasson, Dan Carmon, Swastik Kopparty, David LevitSODA 2023 · 12 citations

Related papers

  1. Approximating text-to-pattern Hamming distancesTimothy M. Chan, Shay Golan, Tomasz Kociumaka, Tsvi Kopelowitz et al.STOC 2020 · 2 citations
  2. Near-Optimal-Time Quantum Algorithms for Approximate Pattern MatchingTomasz Kociumaka, Jakob Nogler, Philip WellnitzSODA 2025 · 1 citation
  3. Small-space and streaming pattern matching with kk editsTomasz Kociumaka, Ely Porat, Tatiana StarikovskayaFOCS 2021 · 13 citations
  4. Faster Approximate Pattern Matching: A Unified ApproachPanagiotis Charalampopoulos, Tomasz Kociumaka, Philip WellnitzFOCS 2020 · 2 citations
  5. Faster Pattern Matching under Edit Distance : A Reduction to Dynamic Puzzle Matching and the Seaweed Monoid of Permutation MatricesPanagiotis Charalampopoulos, Tomasz Kociumaka, Philip WellnitzFOCS 2022 · 8 citations
Dusk over the sea between two cliffs drawn in fine vertical lines