Kernels and Buss's Rule for Vertex Cover
Real solvers for hard problems rarely start with the exponential search. They first run cheap preprocessing that shrinks the instance, and only then search. Kernelization is the theory of preprocessing with a guarantee: after polynomial time, the instance that remains has size bounded by a function of the parameter alone, however large the input was.
Reduction rules and kernels
A reduction rule for a parameterized problem maps an instance to an instance in polynomial time. It is safe if is a YES instance exactly when is. The rules in Bounded Search Trees for Vertex Cover for degree-0 and degree-1 vertices are safe rules.
Definition. A kernelization (or kernel) for a parameterized problem is a polynomial-time algorithm that maps to an equivalent instance with
for a computable function , the size of the kernel. A kernel is polynomial if is a polynomial.
Theorem. A decidable parameterized problem is FPT if and only if it has a kernel.
Proof. If there is a kernel, run it, then solve the instance of size at most by any algorithm: the total time is polynomial plus a function of . Conversely, suppose an algorithm decides the problem in time . Given with : if , the algorithm runs in time at most , which is polynomial, so run it and output a fixed small YES or NO instance accordingly. Otherwise and itself is a kernel of size .
The theorem says kernels exist exactly where FPT algorithms do, but the kernel it builds has the same exponential size as . The interesting question is therefore how small a kernel can be: linear, quadratic, polynomial? The last lesson of this section shows that some FPT problems have no polynomial kernel unless the polynomial hierarchy collapses.
Buss's kernel for vertex cover
The key observation (Buss and Goldsmith, 1993): a vertex of degree more than must be in every cover of size at most . If it were not, all its more than neighbours would be.
BUSS-KERNEL(G, k)
1 repeat until nothing changes
2 delete every isolated vertex
3 if some vertex v has degree > k:
4 delete v; k = k - 1 // v is in every small cover
5 if k < 0: return a trivial NO instance
6 if G has more than k^2 edges: return a trivial NO instance
7 return (G, k)Lemma. If no vertex has degree more than and has a cover of size at most , then has at most edges.
Proof. Each of the at most cover vertices covers at most edges, and every edge is covered.
So the reduced graph has at most edges, and since no vertex is isolated, at most vertices (a sharper count gives : the cover's vertices plus at most neighbours). Every rule runs in polynomial time and is safe, so this is a kernel with edges and vertices. Followed by the search tree on the kernel, it decides vertex cover in time, where pays for the reduction.
The program applies the rules to random graphs that have a planted cover of size , with a few hubs of high degree inside the cover, and reports how much is left.
import random
def planted(n, k, hubs, seed):
rng = random.Random(seed)
C = rng.sample(range(n), k)
E = set()
for i, c in enumerate(C):
deg = rng.randint(30, 60) if i < hubs else rng.randint(2, 6) # a few hubs, the rest low
for v in rng.sample(range(n), deg):
if v != c:
E.add((min(c, v), max(c, v)))
return E
def buss(E, k):
E, forced = set(E), []
while True:
deg = {}
for u, v in E:
deg[u] = deg.get(u, 0) + 1
deg[v] = deg.get(v, 0) + 1
high = [v for v in sorted(deg) if deg[v] > k]
if not high:
break
v = high[0]
forced.append(v)
E = {e for e in E if v not in e}
k -= 1
if k < 0:
return None, None, forced
if len(E) > k * k:
return None, None, forced
return E, k, forced
for seed in range(4):
n, k = 2000, 12
E = planted(n, k, hubs=4, seed=seed)
K, k2, forced = buss(E, k)
verts = {v for e in K for v in e}
print(f"input: {n} vertices, {len(E)} edges, k = {k} -> kernel: {len(verts)} vertices, {len(K)} edges,"
f" k' = {k2} (forced {len(forced)}; bound k'^2 = {k2 * k2})")
print("same graph with budget k = 3:", "NO" if buss(planted(2000, 12, 4, 0), 3)[0] is None else "?")input: 2000 vertices, 185 edges, k = 12 -> kernel: 39 vertices, 31 edges, k' = 8 (forced 4; bound k'^2 = 64)
input: 2000 vertices, 211 edges, k = 12 -> kernel: 37 vertices, 29 edges, k' = 8 (forced 4; bound k'^2 = 64)
input: 2000 vertices, 234 edges, k = 12 -> kernel: 40 vertices, 32 edges, k' = 8 (forced 4; bound k'^2 = 64)
input: 2000 vertices, 215 edges, k = 12 -> kernel: 43 vertices, 35 edges, k' = 8 (forced 4; bound k'^2 = 64)
same graph with budget k = 3: NO
From 2000 vertices only a few dozen remain, independent of . When the budget is too small, the rules notice it (here the fourth forced vertex makes negative) and answer NO without any search.
Kernel plus branching
The kernel and the search tree combine naturally, and the reduction can also be repeated at every node of the search tree (interleaving, Niedermeier and Rossmanith, 2000), which keeps the instances small as drops. The program compares the number of search-tree nodes and the total edge scans with and without the kernel on large sparse graphs.
import random
def planted(n, k, seed):
rng = random.Random(seed)
C = rng.sample(range(n), k)
E = set()
for i, c in enumerate(C):
for v in rng.sample(range(n), n // 40 if i < 3 else 3):
if v != c:
E.add((min(c, v), max(c, v)))
return sorted(E)
def buss(E, k):
while True:
deg = {}
for u, v in E:
deg[u] = deg.get(u, 0) + 1
deg[v] = deg.get(v, 0) + 1
high = next((v for v in sorted(deg) if deg[v] > k), None)
if high is None:
return (E, k) if len(E) <= k * k else (None, k)
E = [e for e in E if high not in e]
k -= 1
if k < 0:
return None, k
def branch(E, k, st):
st["nodes"] += 1
st["scans"] += len(E)
if not E:
return True
if k == 0:
return False
u, v = E[0]
return any(branch([e for e in E if w not in e], k - 1, st) for w in (u, v))
print(" n |E| k plain: nodes scans kernel: |E'| nodes scans")
for n in [1000, 4000, 16000]:
E = planted(n, 10, seed=n)
a = {"nodes": 0, "scans": 0}
r1 = branch(E, 10, a)
K, k2 = buss(E, 10)
b = {"nodes": 0, "scans": 0}
r2 = K is not None and branch(K, k2, b)
assert r1 == r2
print(f"{n:6} {len(E):6} 10 {a['nodes']:13} {a['scans']:9} {len(K):14} {b['nodes']:6} {b['scans']:6}") n |E| k plain: nodes scans kernel: |E'| nodes scans
1000 96 10 2016 65783 21 224 2273
4000 321 10 2047 122326 21 255 2435
16000 1221 10 1984 151974 21 192 1865
Without the kernel each search-tree node rescans the whole edge list, so the cost grows with . With it, the search runs on a graph of at most edges and its cost no longer depends on at all; the reduction itself is a few linear passes.
In C++
Buss's rules with degree counters: when a vertex of degree more than is removed, the degrees of its neighbours drop, and isolated vertices disappear from the count automatically.
#include <cstdio>
#include <set>
#include <utility>
#include <vector>
int main() {
const int n = 5000;
int k = 15;
std::vector<std::set<int>> adj(n);
unsigned s = 99;
auto rnd = [&](int m) { s = s * 1103515245u + 12345u; return int((s >> 8) % m); };
for (int i = 0; i < 15; i++) { // a planted cover {0, ..., 14}
int deg = i < 5 ? 60 : 6;
for (int j = 0; j < deg; j++) {
int v = rnd(n);
if (v != i) { adj[i].insert(v); adj[v].insert(i); }
}
}
long m = 0;
for (auto& a : adj) m += a.size();
std::printf("input: %d vertices, %ld edges, k = %d\n", n, m / 2, k);
bool changed = true;
while (changed && k >= 0) {
changed = false;
for (int v = 0; v < n; v++)
if ((int)adj[v].size() > k) {
for (int u : adj[v]) adj[u].erase(v);
adj[v].clear();
k--;
changed = true;
std::printf("forced vertex %d, k = %d\n", v, k);
if (k < 0) break;
}
}
long edges = 0, verts = 0;
for (auto& a : adj) { edges += a.size(); verts += !a.empty(); }
edges /= 2;
if (k < 0 || edges > (long)k * k) std::printf("NO instance\n");
else std::printf("kernel: %ld vertices, %ld edges, k' = %d (edge bound %d)\n", verts, edges, k, k * k);
}input: 5000 vertices, 358 edges, k = 15
forced vertex 0, k = 14
forced vertex 1, k = 13
forced vertex 2, k = 12
forced vertex 3, k = 11
forced vertex 4, k = 10
kernel: 70 vertices, 60 edges, k' = 10 (edge bound 100)
Test yourself
Why must a vertex of degree more than belong to every vertex cover of size at most ?
- Because it is adjacent to every other vertex
- Because leaving it out forces all of its more than neighbours into the cover
- Because it lies on a cycle
- Because high-degree vertices are always optimal
After Buss's rules, a YES instance has at most how many edges?
Which statement about kernels is a theorem?
- Every NP-hard problem has a polynomial kernel
- A decidable parameterized problem is FPT exactly when it has a kernel
- Kernels always have linear size
- Kernels require randomness
Why does running the search tree on the kernel make its cost independent of ?
- Because the kernel has at most edges, so each node of the tree does work bounded by a function of
- Because the kernel has no edges
- Because the search tree has fewer than nodes
- Because the kernel is a tree