Equivalences between triangle and range query problems

Lech Duraj, Krzysztof Kleiner, Adam Polak, Virginia Vassilevska Williams

This paper, "Equivalences between triangle and range query problems," is a landmark result in fine-grained complexity. It bridges the gap between two seemingly unrelated fields: computational geometry (range queries) and graph theory (triangle counting).

TL;DR

The authors prove that a large class of common range query problems (like counting inversions in a subarray) are computationally equivalent to counting triangles in a graph. This discovery allows them to break the long-standing "Mo's algorithm" barrier, providing the first significant algorithmic improvement for these problems in decades and settling their complexity under the 3SUM hypothesis.

What Problem Does This Paper Address?

In the world of algorithms, "range queries" are a staple. Given an array, you might want to know: How many pairs of equal elements are in the range $[l, r]$? or How many inversions (pairs where $i < j$ but $A[i] > A[j]$) exist in this range?

For years, the "gold standard" for these problems was Mo’s algorithm, a clever technique that solves $q$ queries on an array of size $n$ in $O(n\sqrt{q})$ time. While efficient, researchers suspected it wasn't optimal. Meanwhile, graph theorists have been obsessed with Triangle Counting—finding triples of connected nodes. The best algorithms for this use Fast Matrix Multiplication (FMM) and run in roughly $O(m^{1.41})$ time for $m$ edges.

The authors tackle the question: Are these range query problems actually "harder" than triangle counting, or are they just different views of the same fundamental difficulty?

Methods

The paper relies on fine-grained reductions. The authors show that if you can solve a specific range query problem quickly, you can use that "black box" to count triangles in a graph, and vice versa.

Key techniques include:

  • Segment Tree Decomposition: To turn a range query into a graph problem, the authors decompose array ranges into "base intervals" from a segment tree. These intervals become nodes in a tripartite graph.
  • Tripartite Graph Construction: They build a graph where edges represent occurrences of values within these intervals. A triangle in this graph corresponds exactly to a pair of equal elements (or an inversion) within the queried range.
  • Fast Matrix Multiplication (FMM): By reducing range queries to triangle problems, they can leverage the power of FMM (specifically the $O(m^{2\omega/(\omega+1)})$ bound) to beat the $O(n\sqrt{n})$ barrier.
  • Persistent Data Structures: For the online version of the problems (where queries arrive one by one), they use fully persistent data structures to maintain the "state" of the array across different ranges.

Datasets

As a theoretical computer science paper, it does not use empirical datasets. Instead, it provides mathematical proofs of complexity bounds that apply to any possible input instance.

Key Insights and Ideas

  • The "Bizarre" Complexity Class: The authors identify a "peculiar" running time bound, $O(n^{2\omega/(\omega+1)})$, which is approximately $O(n^{1.41})$ given current matrix multiplication speeds. They show this isn't just a quirk of triangle counting—it's the natural complexity for a whole family of range query problems.
  • Breaking Mo's Algorithm: This is the "aha moment" for competitive programmers. The paper proves that Mo's algorithm is essentially a "combinatorial" approach that ignores the underlying algebraic structure that FMM can exploit.
  • Function Generalization: They show the equivalence holds not just for equality or inversions, but for any "non-axis-orthogonal piecewise polynomial" function. This includes things like $L_1$ distance, thresholds, and more.
  • Listing vs. Detection: They provide the first tight black-box reductions between Triangle Listing (outputting all triangles) and Edge Triangle Detection (checking if an edge belongs to any triangle).

Key Results

  • Equivalence Theorem: Problems like RangeInversionsQuery, RangeEqPairsQuery, and EdgeTriangleCounting are all runtime-equivalent (up to polylogarithmic factors).
  • Improved Upper Bounds: Range queries with $n=q$ can now be solved in $\tilde{O}(n^{1.41})$ time, a significant jump from the previous $O(n^{1.5})$.
  • Conditional Optimality: Under the 3SUM Hypothesis, if the exponent of matrix multiplication $\omega$ were 2, the complexity of these problems would be exactly $n^{4/3}$. The authors show that their equivalence settles the complexity in this ideal case.
  • Online Algorithms: They provide an online algorithm for RangeEqPairsQuery that remains efficient even when queries aren't known in advance.

Limitations and Future Work

  • The $\omega$ Gap: The current best value for $\omega$ is $\approx 2.37$. This leaves a gap between the $n^{1.33}$ lower bound (from 3SUM) and the $n^{1.41}$ upper bound. Closing this gap depends on either better matrix multiplication or a new algorithmic breakthrough.
  • Triangle Counting vs. Edge Counting: A major open question remains: Is counting the total number of triangles in a graph equivalent to counting triangles per edge? The authors suspect yes, but haven't proven it.
  • Online vs. Offline: While they provide online algorithms, it is not yet proven if the online and offline versions of these problems are truly equivalent in terms of their absolute lower bounds.

Summary updated

BibTeX
@inproceedings{duraj2020equivalences,
  author = {Lech Duraj and Krzysztof Kleiner and Adam Polak and Virginia Vassilevska Williams},
  title = {{Equivalences between triangle and range query problems}},
  booktitle = {SODA},
  year = {2020},
  url = {https://openreview.net/forum?id=djFLGJWkzyI},
}

Loading related content...

Figure