Simple Algorithm
Algorithms & Data Structures · Optimal · 28 min

Parameterized Algorithms & Kernelization

Fixed-parameter tractability, bounded search trees and kernels.

Vertex cover is NP-hard, yet with a budget of k=30k = 30 vertices it is solved on graphs with millions of edges, because the exponential part of the work depends on kk alone. kk-clique looks just as innocent, and nobody expects an algorithm of that shape for it. Parameterized complexity explains the difference, with a toolbox (search trees, kernels, color coding, treewidth) and lower bounds that match it.

What you’ll learn

  • Define FPT, XP and kernels, and prove that a decidable problem is FPT exactly when it has a kernel.
  • Analyze branching algorithms through their recurrences, from 2k2^k to 1.4656k1.4656^k for vertex cover, and state the current bounds.
  • Build kernels for vertex cover (Buss's k2k^2 edges, and 2k2k vertices from the half-integral LP), and state why quadratically many edges is essentially optimal.
  • Solve kk-path by color coding in (2e)k(2e)^k times polynomial time, and explain dynamic programming over tree decompositions and Courcelle's theorem.
  • Use W[1]-hardness and the Exponential Time Hypothesis to argue that kk-clique is not FPT and that nO(k)n^{O(k)} is essentially optimal for it.

FPT, XP and kernels

Problem (parameter)StatusBest known
Vertex cover (cover size kk)FPT; kernel with 2k2k verticesO(1.2738k+kn)O(1.2738^k + kn) (Chen, Kanj & Xia, 2010); O∗(1.25284k)O^*(1.25284^k) (Harris & Narayanaswamy, 2024)
kk-path (a simple path on kk vertices)FPT; no polynomial kernel unless coNP ⊆ NP/poly2O(k) m2^{O(k)}\,m by color coding; O∗(2k)O^*(2^k) randomized (Williams, 2009)
kk-clique, kk-independent setW[1]-completenωk/3n^{\omega k/3} with fast matrix multiplication (Nešetřil & Poljak, 1985)
Dominating set (size kk)W[2]-completeabout nkn^{k}
Graph coloring (number of colors)NP-hard already for 3 colorsnot even in XP unless P = NP
Any MSO-definable property (treewidth ww)FPT by Courcelle's theoremf(w)⋅nf(w)\cdot n
O∗O^* hides polynomial factors. The parameter is part of the question: coloring is hopeless parameterized by the number of colors but FPT parameterized by treewidth.
DerivationProof
  1. poly(∣x∣)+h(g(k)) ≤ (h(g(k))+1)⋅poly(∣x∣)\mathrm{poly}(\abs{x}) + h(g(k))\ \le\ \big(h(g(k)) + 1\big)\cdot\mathrm{poly}(\abs{x})

    Kernel ⇒ FPT. Compute the kernel in polynomial time, then decide it by any algorithm. Its size is at most g(k)g(k), so that costs h(g(k))h(g(k)) for some computable hh, and the total has the FPT form:

  2. ∣x∣≥f(k) ⇒ f(k) ∣x∣c ≤ ∣x∣c+1\abs{x} \ge f(k)\ \Rightarrow\ f(k)\,\abs{x}^{c}\ \le\ \abs{x}^{c+1}

    FPT ⇒ kernel. Let an algorithm run in f(k) ∣x∣cf(k)\,\abs{x}^c time. If ∣x∣≥f(k)\abs{x} \ge f(k), it runs within ∣x∣c+1\abs{x}^{c+1}, polynomial time: run it, and output a fixed small yes- or no-instance. Otherwise ∣x∣<f(k)\abs{x} < f(k), and (x,k)(x, k) is itself a kernel of size below f(k)f(k).

So the real question is never whether an FPT problem has a kernel, but how small it can be. Polynomial kernels are the gold standard of provable preprocessing.

Branching numbers

A branching algorithm splits an instance into subinstances with smaller parameters. If every branching splits kk into k−d1,…,k−drk - d_1, \dots, k - d_r, the number of leaves obeys T(k)≤T(k−d1)+⋯+T(k−dr)T(k) \le T(k - d_1) + \dots + T(k - d_r), so T(k)=O(λk)T(k) = O(\lambda^k), where the branching number λ\lambda is the largest real root of:

xd=xd−d1+xd−d2+⋯+xd−dr,d=max⁡idix^{d} = x^{d - d_1} + x^{d - d_2} + \dots + x^{d - d_r}, \qquad d = \max_i d_i
The characteristic equation of the recurrence, the linear recurrence of the lesson Linear Recurrences & Matrix Powers.

Branching on an edge uvuv, taking uu or taking vv, has the vector (1,1)(1, 1): λ=2\lambda = 2, the 2k2^k of the Optimized lesson. Branching on a vertex vv of degree at least 3, taking vv or else all of N(v)N(v), has a vector at least as good as (1,3)(1, 3). When no vertex has degree 3 or more, every component is a path or a cycle, and those are solved directly.

python
def without(adj, S):
    return {v: ns - S for v, ns in adj.items() if v not in S}

def vc_branch(adj, k):
    """adj: {vertex: set of neighbors}. Is there a vertex cover of size <= k?"""
    if k < 0:
        return False                                      # the budget is overspent
    adj = {v: ns for v, ns in adj.items() if ns}         # isolated vertices never help
    if not adj:
        return True
    if k == 0:
        return False
    v = max(adj, key=lambda x: len(adj[x]))
    if len(adj[v]) <= 2:                                  # paths and cycles: solve directly
        need, seen = 0, set()
        for s in adj:
            if s in seen:
                continue
            comp, stack = {s}, [s]
            while stack:
                for w in adj[stack.pop()] - comp:
                    comp.add(w)
                    stack.append(w)
            seen |= comp
            edges = sum(len(adj[w]) for w in comp) // 2
            need += len(comp) // 2 if edges < len(comp) else (len(comp) + 1) // 2
        return need <= k
    return (vc_branch(without(adj, {v}), k - 1)                    # v in the cover
            or vc_branch(without(adj, adj[v]), k - len(adj[v])))   # or all of N(v)

Correct because a cover that omits vv must contain all of N(v)N(v). A path on pp vertices needs ⌊p/2⌋\lfloor p/2 \rfloor cover vertices, a cycle on cc vertices ⌈c/2⌉\lceil c/2 \rceil. Checked against brute force on 1,500 random graphs; an early draft that tested the budget after the empty-graph case wrongly accepted overspent budgets, which is exactly what such tests catch.

DerivationThe branching number of (1, 3)
  1. T(k) ≤ T(k−1)+T(k−3)T(k)\ \le\ T(k - 1) + T(k - 3)

    Taking vv lowers kk by 1; taking N(v)N(v) lowers it by at least 3:

  2. λ3 = λ2+1⇒λ ≈ 1.4656\lambda^3\ =\ \lambda^2 + 1 \quad\Rightarrow\quad \lambda\ \approx\ 1.4656

    Substituting T(k)=λkT(k) = \lambda^k and dividing by λk−3\lambda^{k-3}:

  3. 1.465620 ≈ 2.1×103,220 ≈ 1.05×1061.4656^{20}\ \approx\ 2.1 \times 10^{3}, \qquad 2^{20}\ \approx\ 1.05 \times 10^{6}

    For k=20k = 20, about 2,100 leaves instead of 220≈1062^{20} \approx 10^6:

Predict before you look

A branching rule always creates two subproblems, with parameters k−1k - 1 and k−2k - 2. What is its branching number λ\lambda?

Show the answer

1.618

λ2=λ+1\lambda^2 = \lambda + 1 gives λ=(1+5)/2≈1.618\lambda = (1 + \sqrt5)/2 \approx 1.618, the golden ratio: the leaves count like Fibonacci numbers. Every extra unit of guaranteed decrease in a branch pulls λ\lambda further below 2.

Refined case analyses push further: O(1.2738k+kn)O(1.2738^k + kn) (Chen, Kanj & Xia, 2010), which stood for more than a decade, and O∗(1.25284k)O^*(1.25284^k) (Harris & Narayanaswamy, 2024), which branches while tracking the gap between kk and the LP bound. Below all of them lies a floor: if the Exponential Time Hypothesis holds, no 2o(k) nO(1)2^{o(k)}\,n^{O(1)} algorithm exists, since k≤nk \le n and vertex cover has no 2o(n)2^{o(n)} algorithm under that hypothesis.

Kernels: k², 2k, and no smaller

Buss's rule (Optimized lesson) leaves at most k2k^2 edges and k2+kk^2 + k vertices. Linear programming does better on vertices.

DerivationA kernel with at most 2k vertices
  1. OPT(G) = ∣V1∣+OPT(G[V1/2])\mathrm{OPT}(G)\ =\ \abs{V_1} + \mathrm{OPT}\big(G[V_{1/2}]\big)

    Compute a half-integral optimum x∗x^*; a maximum-matching computation in a bipartite double cover of GG finds one in polynomial time. By the theorem, GG has a cover of size at most kk if and only if G[V1/2]G[V_{1/2}] has one of size at most k′=k−∣V1∣k' = k - \abs{V_1}:

  2. 12 ∣V1/2∣ = LP(G[V1/2]) ≤ OPT(G[V1/2])\tfrac12\,\abs{V_{1/2}}\ =\ \mathrm{LP}\big(G[V_{1/2}]\big)\ \le\ \mathrm{OPT}\big(G[V_{1/2}]\big)

    The LP value of G[V1/2]G[V_{1/2}] is a lower bound on its optimum:

  3. ∣V1/2∣ ≤ 2k′ ≤ 2k\abs{V_{1/2}}\ \le\ 2k'\ \le\ 2k

    So if ∣V1/2∣>2k′\abs{V_{1/2}} > 2k' the answer is no; otherwise (G[V1/2],k′)(G[V_{1/2}], k') is an equivalent instance with few vertices:

Not every FPT problem has a polynomial kernel. Using OR-compositions, Bodlaender, Downey, Fellows and Hermelin (2009) and Fortnow and Santhanam (2011) showed that kk-path has none unless coNP ⊆ NP/poly, which would collapse the polynomial hierarchy.

For vertex cover, Dell and van Melkebeek (2010) proved that kernels with O(k2−ε)O(k^{2-\varepsilon}) bits are impossible under the same assumption, so no kernel has O(k2−ε)O(k^{2-\varepsilon}) edges either: Buss's quadratic number of edges is essentially optimal.

Check your understanding

The LP kernel leaves at most 2k2k vertices, yet kernels with O(k2−ε)O(k^{2-\varepsilon}) edges are ruled out (unless coNP ⊆ NP/poly). Do these results contradict each other?

  1. Yes, so one of them must be wrong
  2. No: the LP kernel cannot actually be computed in polynomial time
  3. No: the lower bound applies only to planar graphs
  4. No: a graph on 2k2k vertices can still have about 2k22k^2 edges, so a linear number of vertices allows a quadratic number of edges
Show the answer

D. No: a graph on 2k2k vertices can still have about 2k22k^2 edges, so a linear number of vertices allows a quadratic number of edges

2k2k vertices span up to (2k2)≈2k2\binom{2k}{2} \approx 2k^2 edges. Encoding such a kernel takes Θ(k2)\Theta(k^2) bits in the worst case, which is exactly what the lower bound says cannot be beaten by a polynomial factor.

Color coding and treewidth

Is there a simple path through exactly kk vertices? Trying all nkn^k vertex sequences is XP. Alon, Yuster and Zwick (1995) found a beautiful randomized trick, color coding: color the vertices at random with kk colors and look only for colorful paths, whose vertices all have different colors. A colorful path is automatically simple, and finding one is a DP over sets of colors, 2k2^k of them, instead of sets of vertices.

python
import math, random

def has_k_path(adj, k, trials):
    """True if a random coloring reveals a simple path on k vertices; never a false 'yes'."""
    n = len(adj)
    for _ in range(trials):
        color = [random.randrange(k) for _ in range(n)]
        ends = [{1 << color[v]} for v in range(n)]       # color sets of colorful paths ending at v
        for _ in range(k - 1):                            # extend every path by one vertex
            nxt = [set() for _ in range(n)]
            for u in range(n):
                for S in ends[u]:
                    for v in adj[u]:
                        if not S >> color[v] & 1:         # v's color unused: still colorful
                            nxt[v].add(S | 1 << color[v])
            ends = nxt
        if any(ends):
            return True
    return False

path5 = [{1}, {0, 2}, {1, 3}, {2, 4}, {3}]
print(has_k_path(path5, 5, trials=int(5 * math.e ** 5) + 1))   # True

One trial is a DP over (vertex, set of colors used): O(2k k m)O(2^k\,k\,m) time. Run against brute force on 800 random graphs with 5ek5e^k trials each, it gave no false answers. On the 5-vertex path a single trial succeeds with probability 5!/55≈3.8%5!/5^5 \approx 3.8\%, so 743 trials miss with probability below 10−1210^{-12}.

DerivationWhy about e^k colorings suffice
  1. Pr⁡[colorful] = k!kk ≥ e−k\Pr[\text{colorful}]\ =\ \frac{k!}{k^k}\ \ge\ e^{-k}

    A fixed path on kk vertices gets kk distinct colors with probability k!/kkk!/k^k, and k!≥(k/e)kk! \ge (k/e)^k:

  2. (1−e−k)t ≤ e−t e−k ≤ δ\big(1 - e^{-k}\big)^{t}\ \le\ e^{-t\,e^{-k}}\ \le\ \delta

    After t=⌈ekln⁡(1/δ)⌉t = \lceil e^k \ln(1/\delta)\rceil independent colorings, it has stayed non-colorful with probability:

  3. O(ek⋅2k k m⋅log⁡(1/δ)) = O((2e)k k m log⁡(1/δ))O\big(e^k \cdot 2^k\,k\,m\cdot\log(1/\delta)\big)\ =\ O\big((2e)^k\,k\,m\,\log(1/\delta)\big)

    Total time, with one-sided error: a yes is always correct. Perfect hash families derandomize it to 2O(k) mlog⁡n2^{O(k)}\,m\log n deterministic time.

A tree decomposition of GG is a tree whose nodes carry bags of vertices, such that every edge of GG lies inside some bag and the bags containing any one vertex form a connected subtree. Its width is the largest bag size minus 1, and the treewidth of GG is the smallest width possible: 1 for a tree with an edge, nn for the n×nn \times n grid.

Dynamic programming runs up the decomposition with a table per bag, indexed by the states of the bag's vertices. For maximum independent set the state is which vertices of the bag are in the set, at most 2w+12^{w+1} entries per bag, giving O(2w wO(1) n)O(2^w\,w^{O(1)}\,n) time from a decomposition of width ww with O(n)O(n) nodes.

Lower bounds: W[1] and the Exponential Time Hypothesis

NP-hardness cannot tell vertex cover from clique: both are NP-complete. Parameterized complexity uses parameterized reductions, maps (x,k)↦(x′,k′)(x, k) \mapsto (x', k') computable in f(k) ∣x∣O(1)f(k)\,\abs{x}^{O(1)} time with k′≤g(k)k' \le g(k), which carry FPT algorithms backward. The class W[1] is the closure of kk-clique under such reductions (Downey & Fellows, 1995), and FPT≠W[1]\mathrm{FPT} \ne \mathrm{W[1]} is the standard conjecture, the parameterized analogue of P ≠ NP.

ProblemAlgorithmRuled out under ETH
Vertex cover1.2738k nO(1)1.2738^k\,n^{O(1)}2o(k) nO(1)2^{o(k)}\,n^{O(1)}
kk-cliquenO(k)n^{O(k)}f(k) no(k)f(k)\,n^{o(k)}
Planar vertex cover2O(k) nO(1)2^{O(\sqrt k)}\,n^{O(1)}2o(k) nO(1)2^{o(\sqrt k)}\,n^{O(1)}
Independent set on treewidth ww2w wO(1) n2^{w}\,w^{O(1)}\,n2o(w) nO(1)2^{o(w)}\,n^{O(1)}; SETH even rules out (2−ε)w nO(1)(2 - \varepsilon)^w\,n^{O(1)} (Lokshtanov, Marx & Saurabh, 2011)
Where the two columns meet, the algorithm is optimal up to the constant in the exponent, assuming the hypothesis.
Check your understanding

Why does ETH rule out a 2o(k) nO(1)2^{o(k)}\,n^{O(1)} algorithm for vertex cover?

  1. Because vertex cover is W[1]-hard
  2. Because the cover size kk is at most nn, so such an algorithm would solve vertex cover in 2o(n)2^{o(n)} time, which ETH forbids via the linear-size reduction from 3-SAT
  3. Because every branching algorithm needs at least 2k2^k leaves
  4. Because kernels cannot be smaller than 2k2k vertices
Show the answer

B. Because the cover size kk is at most nn, so such an algorithm would solve vertex cover in 2o(n)2^{o(n)} time, which ETH forbids via the linear-size reduction from 3-SAT

On graphs from the sparsified 3-SAT reduction, k=O(n)k = O(n), so 2o(k)2^{o(k)} would be 2o(n)2^{o(n)}, contradicting ETH. The lower bound concerns all algorithms, not just branching.

Key takeaways

  • FPT means f(k)⋅nO(1)f(k)\cdot n^{O(1)}, XP means nf(k)n^{f(k)}; a decidable problem is FPT exactly when it has a kernel, so the real question is how small a kernel can be.
  • Branching algorithms run in O(λk)O(\lambda^k), with λ\lambda the largest root of the characteristic equation: 22 for (1,1)(1, 1), 1.46561.4656 for (1,3)(1, 3); the best vertex-cover bounds are 1.2738k1.2738^k (2010) and 1.25284k1.25284^k (2024).
  • Vertex cover has kernels with k2k^2 edges (Buss) and 2k2k vertices (Nemhauser–Trotter LP); O(k2−ε)O(k^{2-\varepsilon}) edges is impossible unless coNP ⊆ NP/poly, and kk-path has no polynomial kernel at all.
  • Color coding finds kk-paths in O((2e)k k m)O((2e)^k\,k\,m) expected time; DP over tree decompositions and Courcelle's theorem make MSO-definable problems linear for bounded treewidth.
  • kk-clique is W[1]-complete, and under ETH it has no f(k) no(k)f(k)\,n^{o(k)} algorithm, nor does vertex cover have a 2o(k) nO(1)2^{o(k)}\,n^{O(1)} one.

Check yourself

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

Question 1

kk-clique can be solved in O(k2 nk)O(k^2\, n^k) time by checking every set of kk vertices. What does this say about its parameterized complexity?

  1. It is FPT, since the running time is polynomial for each fixed kk
  2. It is in XP; it is FPT only if the degree of the polynomial could be made independent of kk, which W[1]-hardness makes unlikely
  3. It is not even in XP
  4. It has a polynomial kernel
Show the answer

B. It is in XP; it is FPT only if the degree of the polynomial could be made independent of kk, which W[1]-hardness makes unlikely

nkn^k is XP: polynomial for each fixed kk, with degree growing with kk. FPT demands f(k) ncf(k)\,n^{c} with a fixed cc. kk-clique is W[1]-complete, and under ETH not even f(k) no(k)f(k)\,n^{o(k)} is possible.

Question 2

Why does branching on a vertex of degree at least 3 give O(1.4656k)O(1.4656^k) leaves rather than O(2k)O(2^k)?

  1. Because it branches three ways instead of two
  2. Because high-degree vertices are always in the cover
  3. Because one of its two branches puts at least 3 vertices into the cover, lowering kk by at least 3
  4. Because paths and cycles are solved by brute force
Show the answer

C. Because one of its two branches puts at least 3 vertices into the cover, lowering kk by at least 3

The recurrence T(k)≤T(k−1)+T(k−3)T(k) \le T(k - 1) + T(k - 3) grows like λk\lambda^k with λ3=λ2+1\lambda^3 = \lambda^2 + 1, so λ≈1.4656\lambda \approx 1.4656. Branching on an edge lowers kk by only 1 in each branch: T(k)≤2T(k−1)T(k) \le 2T(k - 1).

Question 3

Which statement about kernels is true?

  1. Every FPT problem has a polynomial kernel
  2. A kernel must have size O(k)O(k)
  3. A decidable parameterized problem is FPT if and only if it has a kernel
  4. Computing a kernel solves the problem
Show the answer

C. A decidable parameterized problem is FPT if and only if it has a kernel

An FPT algorithm can be turned into a kernel of size f(k)f(k), and a kernel plus brute force gives an FPT algorithm. Whether a polynomial kernel exists is a finer question: kk-path has none unless coNP ⊆ NP/poly.

Question 4

Why does color coding search for colorful paths, whose vertices all have different colors, instead of simple paths?

  1. Because colorful paths are shorter
  2. Because a colorful path is automatically simple, and the DP only needs to remember the set of colors used, 2k2^k possibilities, instead of the set of vertices used
  3. Because random colors make the graph sparser
  4. Because every simple path is colorful
Show the answer

B. Because a colorful path is automatically simple, and the DP only needs to remember the set of colors used, 2k2^k possibilities, instead of the set of vertices used

Repeated vertices would repeat a color, so colorful implies simple. Tracking colors costs 2k2^k states per vertex rather than (nk)\binom{n}{k} vertex sets, and a fixed kk-path is colorful with probability k!/kk≥e−kk!/k^k \ge e^{-k}, so O(ek)O(e^k) random colorings suffice.

Further reading

  • M. Cygan, F. V. Fomin, Ł. Kowalik, D. Lokshtanov, D. Marx, M. Pilipczuk, M. Pilipczuk & S. Saurabh, Parameterized Algorithms (Springer, 2015).
  • R. G. Downey & M. R. Fellows, Fundamentals of Parameterized Complexity (Springer, 2013).
  • N. Alon, R. Yuster & U. Zwick, "Color-coding," Journal of the ACM 42(4) (1995), 844–856.
  • J. Chen, I. A. Kanj & G. Xia, "Improved upper bounds for vertex cover," Theoretical Computer Science 411(40–42) (2010), 3736–3756.
  • G. L. Nemhauser & L. E. Trotter, "Vertex packings: structural properties and algorithms," Mathematical Programming 8 (1975).