Simple Algorithm
Algorithms & Data Structures · Optimal · 28 min

Fine-Grained Complexity

SETH, 3SUM and APSP: why some polynomial algorithms seem impossible to beat.

The edit distance of two strings has been computed by the same quadratic dynamic program since the 1970s, and decades of effort have shaved off only logarithmic factors. Is a faster algorithm waiting to be found? Fine-grained complexity answers "probably not" with a theorem: an O(n1.99)O(n^{1.99}) algorithm for edit distance would also solve CNF-SAT faster than almost anyone believes possible.

What you’ll learn

  • State SETH, the 3SUM conjecture and the APSP conjecture precisely, with their models, and define fine-grained reductions.
  • Prove that SETH implies the orthogonal vectors conjecture by Williams's split-and-list reduction, and trace its consequences for edit distance, LCS and graph diameter.
  • Reduce 3SUM to collinearity of points, and summarize what is known about 3SUM's true complexity.
  • Explain the subcubic equivalences among APSP, the min-plus product and negative-triangle detection.
  • Use conditional lower bounds in algorithm design: when to stop looking for a better exponent, and which routes (parameters, word-level parallelism, approximation) remain open.

Hardness inside P

NP-completeness separates polynomial time from (presumably) exponential time, and says nothing about exponents: is edit distance Θ(n2)\Theta(n^2), or could it be O(n1.5)O(n^{1.5})? Proving that it needs n2−o(1)n^{2-o(1)} time unconditionally is far beyond current techniques.

Fine-grained complexity does what NP-completeness did: it picks a few problems believed to be hard for exact exponents and connects other problems to them by reductions that preserve exponents.

HypothesisStatement (unproven)Best algorithm known
SETH (Impagliazzo & Paturi, 2001)for every ε>0\varepsilon > 0 there is a kk such that kk-SAT on nn variables cannot be solved in O(2(1−ε)n)O(2^{(1-\varepsilon)n}) time2(1−Θ(1/k))n2^{(1 - \Theta(1/k))n} for kk-SAT (PPSZ)
3SUM conjecturedeciding whether nn integers in {−n3,…,n3}\{-n^3, \dots, n^3\} contain a+b+c=0a + b + c = 0 needs n2−o(1)n^{2-o(1)} time on the word RAMn2(log⁡log⁡n)O(1)/log⁡2nn^2(\log\log n)^{O(1)}/\log^2 n (Chan, 2018)
APSP conjectureall-pairs shortest paths on nn vertices with integer weights in {−nc,…,nc}\{-n^c, \dots, n^c\} needs n3−o(1)n^{3-o(1)} time on the word RAMn3/2Ω(log⁡n)n^3/2^{\Omega(\sqrt{\log n})}, randomized (Williams, 2014)
No reductions among the three hypotheses are known. The o(1)o(1) matters: the original 3SUM conjecture claimed Ω(n2)\Omega(n^2), which log-factor algorithms refuted; what is conjectured impossible is a truly subquadratic O(n2−ε)O(n^{2-\varepsilon}).

SETH and orthogonal vectors

DerivationProof: split and list
  1. uα[j]={0if α makes a literal of Cj true,1otherwise.u_\alpha[j] = \begin{cases} 0 & \text{if } \alpha \text{ makes a literal of } C_j \text{ true,} \\ 1 & \text{otherwise.} \end{cases}

    Take a CNF formula with variables x1,…,xnx_1, \dots, x_n and clauses C1,…,CmC_1, \dots, C_m. Split the variables into two halves. For each assignment α\alpha of the first half build uα∈{0,1}mu_\alpha \in \{0, 1\}^m, and for each assignment β\beta of the second half build vβv_\beta the same way:

  2. uα⋅vβ=0  ⟺  (α,β) satisfies every clauseu_\alpha \cdot v_\beta = 0 \iff (\alpha, \beta) \text{ satisfies every clause}

    Coordinate jj contributes to uα⋅vβu_\alpha \cdot v_\beta exactly when neither half satisfies CjC_j, that is, when the combined assignment falsifies CjC_j:

  3. O(N2−ε poly(m)) = O(2(1−ε/2)n poly(m))O\big(N^{2-\varepsilon}\,\mathrm{poly}(m)\big)\ =\ O\big(2^{(1 - \varepsilon/2)n}\,\mathrm{poly}(m)\big)

    So the formula is satisfiable exactly when the OV instance with N=2n/2N = 2^{n/2} vectors per side and d=md = m has an orthogonal pair, and building it takes O(N m n)O(N\,m\,n) time. A fast OV algorithm then gives:

  4. 2γn⋅2(1−ε/2)n poly(n) = O(2(1−ε/4)n poly(n))2^{\gamma n}\cdot 2^{(1-\varepsilon/2)n}\,\mathrm{poly}(n)\ =\ O\big(2^{(1-\varepsilon/4)n}\,\mathrm{poly}(n)\big)

    Few clauses. A kk-CNF may have up to about nkn^k clauses, but the sparsification lemma (Impagliazzo, Paturi & Zane, 2001) splits it, for any γ>0\gamma > 0, into 2γn2^{\gamma n} kk-CNFs with O(n)O(n) clauses each, whose disjunction is equivalent to it. With γ=ε/4\gamma = \varepsilon/4 the total time is:

python
from itertools import product

def cnf_to_ov(n, clauses):
    """Split-and-list reduction: variables 1..n, clauses as lists of DIMACS literals."""
    def vectors(variables):
        out = []
        for bits in product([False, True], repeat=len(variables)):
            value = dict(zip(variables, bits))
            out.append([0 if any(value.get(abs(l)) == (l > 0) for l in c) else 1   # 0: this half satisfies c
                        for c in clauses])
        return out
    half = n // 2
    return vectors(range(1, half + 1)), vectors(range(half + 1, n + 1))

def has_orthogonal_pair(A, B):                      # the O(N^2 d) brute force
    return any(all(a * b == 0 for a, b in zip(u, v)) for u in A for v in B)

F1 = [[1, 2], [-1, 3], [-2, -3], [1, -3]]           # satisfiable: x1 = 1, x2 = 0, x3 = 1
F2 = [[1, 2], [-1, 2], [1, -2], [-1, -2]]           # unsatisfiable
print(has_orthogonal_pair(*cnf_to_ov(3, F1)), has_orthogonal_pair(*cnf_to_ov(2, F2)))   # True False

For F1, the first half's assignment x1=1x_1 = 1 gives u=(0,1,1,0)u = (0, 1, 1, 0) and the second half's x2=0,x3=1x_2 = 0, x_3 = 1 gives v=(1,0,0,1)v = (1, 0, 0, 1): orthogonal, and together a satisfying assignment. The reduction agreed with brute-force SAT on 3,000 random formulas.

Since 2005, OV has been reduced to dozens of problems, each by gadgets that turn vectors into strings, curves or graphs, so each of these lower bounds holds under SETH:

ProblemClassic algorithmRuled out under SETH
Edit distanceO(n2)O(n^2) dynamic programmingO(n2−ε)O(n^{2-\varepsilon}) (Backurs & Indyk, 2015)
Longest common subsequenceO(n2)O(n^2)O(n2−ε)O(n^{2-\varepsilon}) (Abboud, Backurs & Vassilevska Williams, 2015; Bringmann & Künnemann, 2015)
Fréchet distance between two curvesO(n2log⁡n)O(n^2\log n) (Alt & Godau, 1995)O(n2−ε)O(n^{2-\varepsilon}) (Bringmann, 2014)
Diameter of a sparse graph: is it 2 or 3?BFS from every vertex, O(nm)O(nm)O(m2−ε)O(m^{2-\varepsilon}), hence any (32−ε)(\tfrac32 - \varepsilon)-approximation in that time (Roditty & Vassilevska Williams, 2013)
Orthogonal vectors itselfN2−1/O(log⁡(d/log⁡N))N^{2 - 1/O(\log(d/\log N))} (Abboud, Williams & Yu, 2015)N2−ε poly(d)N^{2-\varepsilon}\,\mathrm{poly}(d)
The OV algorithm in the last row is subquadratic only when d=O(log⁡N)d = O(\log N) is small: the conjecture concerns d=clog⁡Nd = c\log N for every constant cc.
Check your understanding

OV reduces to edit distance: OV instances become pairs of strings whose edit distance reveals the answer. What would an O(n1.5)O(n^{1.5}) edit-distance algorithm imply?

  1. Nothing about OV, because the reduction goes the other way
  2. That P = NP
  3. A truly subquadratic algorithm for OV, and therefore that SETH is false
  4. A faster OV algorithm, while SETH could still hold
Show the answer

C. A truly subquadratic algorithm for OV, and therefore that SETH is false

A reduction from OV to edit distance carries fast edit-distance algorithms back to OV: O(N2−ε)O(N^{2-\varepsilon}) for OV, and by Williams's theorem a 2(1−δ)n2^{(1-\delta)n} algorithm for every kk-SAT, refuting SETH.

3SUM and geometry

3SUM asks whether nn integers contain three, a+b+c=0a + b + c = 0. Sorting and two pointers solve it in O(n2)O(n^2) time (the lesson 3SUM & the k-SUM Problem). Gajentaan and Overmars (1995) called a problem 3SUM-hard when 3SUM reduces to it with o(n2)o(n^2) overhead, and found such problems all over computational geometry. The first is the simplest.

DerivationThree collinear points is 3SUM-hard
  1. b3−a3b−a = a2+ab+b2\frac{b^3 - a^3}{b - a}\ =\ a^2 + ab + b^2

    Map each number xx to the point (x,x3)(x, x^3). For a≠ba \ne b, the slope between their points is:

  2. a2+ab+b2=a2+ac+c2  ⟺  (b−c)(a+b+c)=0  ⟺  a+b+c=0a^2 + ab + b^2 = a^2 + ac + c^2 \iff (b - c)(a + b + c) = 0 \iff a + b + c = 0

    Three points with distinct a,b,ca, b, c are collinear exactly when the slopes from aa to bb and from aa to cc agree:

  3. 3SUM ≤O(n) three collinear points among n\text{3SUM} \ \le_{O(n)}\ \text{three collinear points among } n

    So, for distinct integers, a 3SUM triple exists exactly when three of the nn points are collinear: a linear-time reduction. For example, 3+5−8=03 + 5 - 8 = 0, and (3,27)(3, 27), (5,125)(5, 125), (−8,−512)(-8, -512) lie on one line of slope 49.

Gajentaan and Overmars's list runs from covering a region by triangles to planar motion planning, and Pătraşcu (2010) extended 3SUM-hardness to dynamic data structures and to listing triangles in graphs. Yet 3SUM itself is less hard than it was once thought:

Check your understanding

You want to show that a new geometry problem PP is 3SUM-hard. Which reduction must you give?

  1. A reduction from PP to 3SUM, solving PP with a 3SUM algorithm
  2. A reduction from 3SUM to PP: turn any 3SUM instance into an instance of PP in o(n2)o(n^2) time, so that a fast algorithm for PP would solve 3SUM fast
  3. Either direction works
  4. A proof that PP is in NP
Show the answer

B. A reduction from 3SUM to PP: turn any 3SUM instance into an instance of PP in o(n2)o(n^2) time, so that a fast algorithm for PP would solve 3SUM fast

Hardness flows along reductions from the hard problem: if 3SUM reduces to PP cheaply, an O(n2−ε)O(n^{2-\varepsilon}) algorithm for PP would give one for 3SUM, contradicting the conjecture. The collinearity reduction above has this shape.

APSP and subcubic equivalences

All-pairs shortest paths takes O(n3)O(n^3) time with Floyd–Warshall, and up to logarithmic factors it is the same problem as the min-plus product Cij=min⁡k(Aik+Bkj)C_{ij} = \min_k (A_{ik} + B_{kj}): repeated squaring of the weight matrix computes all distances with O(log⁡n)O(\log n) products, and one product is a shortest-path computation in a three-layer graph (the lesson All-Pairs Shortest Paths). Unlike the ordinary matrix product, the min-plus product has no known truly subcubic algorithm: fast matrix multiplication (ω<2.371339\omega < 2.371339 as of 2025) relies on subtraction, which (min⁡,+)(\min, +) lacks.

DerivationWhy a triangle detector is as strong as APSP (sketch)
  1. ∃ i≠j: (W⋆W)ij+Wji<0  ⟺  a negative triangle exists\exists\, i \ne j:\ (W \star W)_{ij} + W_{ji} < 0 \iff \text{a negative triangle exists}

    Easy direction. One min-plus product finds a negative triangle: a triangle through ii and jj is negative exactly when the best two-step path from ii to jj plus the edge back is negative.

  2. Cij<Tij  ⟺  ∃ k: Aik+Bkj−Tij<0C_{ij} < T_{ij} \iff \exists\, k:\ A_{ik} + B_{kj} - T_{ij} < 0

    Hard direction, step 1. To compute C=A⋆BC = A \star B, it is enough to answer, for every pair (i,j)(i, j) at once, whether Cij<TijC_{ij} < T_{ij} for given thresholds; binary search over the thresholds, all pairs in parallel, then recovers every entry in O(log⁡M)O(\log M) rounds. Each round is a negative-triangle question on a tripartite graph with weights AikA_{ik}, BkjB_{kj} and −Tij-T_{ij}:

  3. T(n)=n3−ε ⇒ n2 T(n1/3)=n3−ε/3T(n) = n^{3-\varepsilon}\ \Rightarrow\ n^2\,T(n^{1/3}) = n^{3 - \varepsilon/3}

    Hard direction, step 2. A detector only says whether a negative triangle exists, not for which pairs. Splitting the vertex sets into blocks and running the detector on triples of blocks, discarding each pair once a triangle through it is found, turns a detector running in T(n)T(n) time into APSP in O(n2 T(n1/3)log⁡M)O(n^2\,T(n^{1/3})\log M) time, truly subcubic whenever TT is:

The same circle of ideas places graph radius and median among the APSP-equivalent problems (Abboud, Grandoni & Vassilevska Williams, 2015), while diameter is not known to be APSP-hard. Some problems, such as finding a triangle of total weight exactly zero, are hard under both the 3SUM and the APSP conjectures. In unweighted undirected graphs APSP takes O~(nω)\tilde O(n^\omega) time (Seidel, 1995): the weights carry the hardness.

Check your understanding

Triangle detection in an unweighted graph takes O(nω)O(n^\omega) time with fast matrix multiplication, and ω<2.372\omega < 2.372. Why does this not refute the APSP conjecture?

  1. Because ω\omega might still equal 3
  2. Because triangle detection is NP-hard
  3. Because O(nω)O(n^\omega) is not subcubic
  4. Because the conjecture concerns weighted graphs; with weights, triangle detection becomes negative-triangle detection, where the subtraction behind fast matrix multiplication is not available
Show the answer

D. Because the conjecture concerns weighted graphs; with weights, triangle detection becomes negative-triangle detection, where the subtraction behind fast matrix multiplication is not available

Unweighted triangle detection is a Boolean matrix product, which fast matrix multiplication handles. Negative-triangle detection needs the min-plus product, and that equivalence with APSP is exactly what the theorem states.

What it means for algorithm design

A conditional lower bound changes what you look for. If your problem is SETH-hard for n2−εn^{2-\varepsilon}, stop hunting for a better exponent on arbitrary inputs: such an algorithm would be a breakthrough on CNF-SAT, one of the most studied problems in computer science. The productive routes lie elsewhere, and edit distance shows all of them:

RouteEdit distance of two strings of length nn
Exploit a parameterif the distance dd is small, O(nd)O(nd) time (Ukkonen, 1985)
Word-level parallelismbit-parallel dynamic programming updates a whole machine word of cells per operation, for O(n2/w)O(n^2/w) (Myers, 1999)
Shave logarithmsthe Four Russians technique gives O(n2/log⁡n)O(n^2/\log n) (Masek & Paterson, 1980)
Approximateconstant-factor approximations in truly subquadratic time (Chakraborty, Das, Goldenberg, Koucký & Saks, 2018), later in near-linear time (Andoni & Nosatzki, 2020)
None of these contradicts SETH: each changes the question (a parameter, a machine model's word size, a logarithm, an approximation) rather than the exponent of the exact worst case.

The hypotheses themselves are debated. SETH is far stronger than P ≠ NP, and some researchers doubt it; the 3SUM conjecture had to be weakened once already. Still, a conditional lower bound is strong evidence: refuting it would itself be a celebrated result, with faster algorithms for SAT, 3SUM or APSP as a consequence. The lesson Edit Distance & Its Limits applies all of this to one problem in detail.

Predict before you look

The quadratic edit-distance algorithm fills n2n^2 table cells. At 10810^8 cells per second, how many seconds does it take for two strings of 10510^5 characters?

Show the answer

100

(105)2=1010(10^5)^2 = 10^{10} cells at 10810^8 per second take 100 seconds. Under SETH no exact algorithm beats this by a polynomial factor on arbitrary inputs, but a bit-parallel implementation with 64-bit words divides it by up to 64, and a small edit distance changes the picture entirely.

Key takeaways

  • Fine-grained complexity classifies polynomial problems by exponent, through reductions that preserve exponents from three unproven hypotheses: SETH, the 3SUM conjecture and the APSP conjecture.
  • Williams's split-and-list reduction shows that SETH implies the OV conjecture; OV in turn rules out truly subquadratic algorithms for edit distance, LCS, Fréchet distance and approximate diameter, unless SETH fails.
  • 3SUM reduces to many geometric problems, such as three collinear points via x↦(x,x3)x \mapsto (x, x^3); its true complexity is subtle, with near-linear decision trees and n2/log⁡2−o(1)nn^2/\log^{2-o(1)} n algorithms.
  • APSP, min-plus product and negative-triangle detection stand or fall together; the weights carry the hardness, since unweighted versions use fast matrix multiplication.
  • A conditional lower bound redirects effort toward parameters, word-level parallelism, logarithmic savings and approximation.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Which statement is the Strong Exponential Time Hypothesis?

  1. 3-SAT cannot be solved in 2o(n)2^{o(n)} time
  2. For every ε>0\varepsilon > 0 there is a kk such that kk-SAT on nn variables cannot be solved in O(2(1−ε)n)O(2^{(1-\varepsilon)n}) time
  3. P ≠ NP
  4. CNF-SAT needs exactly 2n2^n steps
Show the answer

B. For every ε>0\varepsilon > 0 there is a kk such that kk-SAT on nn variables cannot be solved in O(2(1−ε)n)O(2^{(1-\varepsilon)n}) time

SETH says the base of the exponential must approach 2 as the clause width grows. It implies ETH, the first option, which only forbids subexponential time, and both are far stronger than P ≠ NP.

Question 2

The split-and-list reduction turns a CNF formula with nn variables and mm clauses into an OV instance. How large is it?

  1. nn vectors of dimension mm
  2. 2n/22^{n/2} vectors per side, of dimension mm
  3. 2n2^n vectors per side, of dimension nn
  4. mm vectors per side, of dimension 2n/22^{n/2}
Show the answer

B. 2n/22^{n/2} vectors per side, of dimension mm

One vector per assignment of each half, with one coordinate per clause. Brute-force OV on it costs (2n/2)2=2n(2^{n/2})^2 = 2^n, matching brute-force SAT, so beating brute-force OV by a polynomial factor beats brute-force SAT by an exponential one.

Question 3

The reduction from 3SUM to collinearity maps each number xx to the point (x,x3)(x, x^3). Why a cubic curve?

  1. Any curve would do, for instance (x,x2)(x, x^2)
  2. Because for distinct a,b,ca, b, c, the points (a,a3)(a, a^3), (b,b3)(b, b^3), (c,c3)(c, c^3) are collinear exactly when a+b+c=0a + b + c = 0
  3. Because cubes keep the coordinates within the word size
  4. Because a cubic curve has no three collinear points
Show the answer

B. Because for distinct a,b,ca, b, c, the points (a,a3)(a, a^3), (b,b3)(b, b^3), (c,c3)(c, c^3) are collinear exactly when a+b+c=0a + b + c = 0

Slopes on the cubic are a2+ab+b2a^2 + ab + b^2, and equal slopes factor as (b−c)(a+b+c)=0(b - c)(a + b + c) = 0. On the parabola (x,x2)(x, x^2) the slope is a+ba + b, and equal slopes force b=cb = c: three distinct points on a parabola are never collinear, so it encodes nothing.

Question 4

APSP, the min-plus product and negative-triangle detection are equivalent under subcubic reductions. Which statement follows?

  1. An O(n2.9)O(n^{2.9}) algorithm for negative-triangle detection would give an O(n3−ε)O(n^{3-\varepsilon}) algorithm for APSP
  2. Negative-triangle detection needs Ω(n3)\Omega(n^3) time
  3. APSP can be solved in O(nω)O(n^\omega) time with fast matrix multiplication
  4. Triangle detection in unweighted graphs is as hard as APSP
Show the answer

A. An O(n2.9)O(n^{2.9}) algorithm for negative-triangle detection would give an O(n3−ε)O(n^{3-\varepsilon}) algorithm for APSP

A detector running in T(n)T(n) gives APSP in O(n2 T(n1/3)log⁡M)O(n^2\,T(n^{1/3})\log M) time, which is O(n3−0.1/3log⁡M)O(n^{3-0.1/3}\log M) for T(n)=n2.9T(n) = n^{2.9}. Equivalence transfers speedups in both directions; it proves no lower bound by itself.

Further reading

  • V. Vassilevska Williams, "On some fine-grained questions in algorithms and complexity," Proceedings of the International Congress of Mathematicians (ICM 2018) (2019).
  • R. Williams, "A new algorithm for optimal 2-constraint satisfaction and its implications," Theoretical Computer Science 348(2–3) (2005), 357–365.
  • A. Backurs & P. Indyk, "Edit distance cannot be computed in strongly subquadratic time (unless SETH is false)," Proceedings of STOC (2015).
  • A. Gajentaan & M. H. Overmars, "On a class of O(n²) problems in computational geometry," Computational Geometry: Theory and Applications 5(3) (1995).
  • V. Vassilevska Williams & R. Williams, "Subcubic equivalences between path, matrix, and triangle problems," Journal of the ACM 65 (2018).