TExcelTAD
Home › Parameterized & Fine-Grained Complexity › Iterative Compression

Iterative Compression

Branching needs a small obstruction to branch on. Some problems do not offer one: for odd cycle transversal (delete kk vertices to make a graph bipartite) the obstructions are odd cycles of any length, and no lemma like the one for feedback vertex set bounds the choices. Iterative compression, introduced by Reed, Smith and Vetta (2004) for exactly this problem, takes a different route: it is easier to improve a solution that is one vertex too large than to find one from nothing, because the too-large solution reveals the structure of the graph.

The scheme

Call a graph problem hereditary if a solution for GG restricted to an induced subgraph is a solution for that subgraph. Vertex cover, feedback vertex set and odd cycle transversal are all hereditary: deleting vertices never creates new edges or cycles.

COMPRESSION for a problem: given GG, kk and a solution ZZ with ∣Z∣=k+1\lvert Z \rvert = k + 1, find a solution of size at most kk or report that none exists.

Order the vertices v1,…,vnv_1, \ldots, v_n and let Gi=G[{v1,…,vi}]G_i = G[\{v_1, \ldots, v_i\}].

text
ITERATIVE-COMPRESSION(G, k)
1  X = empty set                                // a solution for G_0
2  for i = 1 to n
3      Z = X + v_i                              // a solution for G_i of size <= k + 1
4      if |Z| <= k:  X = Z;  continue
5      X = COMPRESS(G_i, k, Z)
6      if X = NONE:  return NO                  // G_i, hence G, has no solution of size k
7  return X

Line 3 works for vertex deletion problems: adding viv_i to a solution of Gi−1G_{i-1} gives a solution of GiG_i. Line 6 uses heredity: a solution of size kk for GG would restrict to one for GiG_i. So the whole problem costs nn calls to COMPRESS, and it suffices to make compression FPT.

Guessing the overlap

COMPRESS starts by guessing how the new solution XX meets the old one ZZ. For each of the 2k+12^{k+1} subsets Y⊆ZY \subseteq Z, look for a solution XX with X∩Z=YX \cap Z = Y. The vertices of Z∖YZ \setminus Y are now forbidden: they must stay out of XX. What remains is a disjoint version of the problem, in which the forbidden part is small and the rest of the graph is simple (because ZZ was a solution).

For vertex cover the disjoint version is trivial, which makes it a clean first example. ZZ is a cover, so V∖ZV \setminus Z is independent. Fix YY and let W=Z∖YW = Z \setminus Y.

  • If WW contains an edge, no cover avoids both endpoints: reject this guess.
  • Otherwise every edge inside ZZ has an endpoint in YY, and every edge between WW and V∖ZV \setminus Z must be covered by its endpoint outside ZZ. So the best cover with X∩Z=YX \cap Z = Y is exactly X=Y∪N(W)X = Y \cup N(W), where N(W)N(W) lies outside ZZ.

So compression for vertex cover takes O(2k(n+m))O(2^{k} (n + m)) time, and the whole algorithm O(2kn(n+m))O(2^k n (n + m)). That is worse than branching, but the scheme is what matters. The program traces it on a small graph.

python · try it yourself
from itertools import combinations

def compress(adj, verts, k, Z):
    best, guesses = None, 0
    for r in range(len(Z) + 1):
        for Y in combinations(sorted(Z), r):
            guesses += 1
            W = set(Z) - set(Y)
            if any(b in adj[a] for a in W for b in W):
                continue                                    # an edge inside W: impossible
            X = set(Y) | {b for a in W for b in adj[a] if b in verts}
            if len(X) <= k and (best is None or len(X) < len(best)):
                best = X
    return best, guesses

def iterative_compression(adj, order, k, trace=False):
    X, verts, total = set(), set(), 0
    for v in order:
        verts.add(v)
        Z = X | {v}
        if len(Z) <= k:
            X = Z
        else:
            X, g = compress(adj, verts, k, Z)
            total += g
            if X is None:
                return None, total
        if trace:
            print(f"add {v}: solution {sorted(X)}")
    return X, total

edges = [(0, 1), (1, 2), (2, 3), (3, 0), (1, 4), (4, 5), (5, 6), (6, 4), (3, 7)]
adj = {v: set() for v in range(8)}
for a, b in edges:
    adj[a].add(b); adj[b].add(a)
X, g = iterative_compression(adj, range(8), 4, trace=True)
print("k = 4:", sorted(X), "after", g, "guesses")
X, g = iterative_compression(adj, range(8), 3)
print("k = 3:", X, "after", g, "guesses")
add 0: solution [0]
add 1: solution [0, 1]
add 2: solution [0, 1, 2]
add 3: solution [0, 1, 2, 3]
add 4: solution [1, 3]
add 5: solution [1, 3, 5]
add 6: solution [1, 3, 5, 6]
add 7: solution [1, 3, 4, 5]
k = 4: [1, 3, 4, 5] after 64 guesses
k = 3: None after 48 guesses

The trace shows the invariant: after step ii the set is a cover of GiG_i with at most kk vertices. With k=3k = 3 the compression of some GiG_i fails, which proves that GG itself has no cover of size 3 (the 4-cycle and the triangle are disjoint and need 2+22 + 2 vertices).

Checking against brute force

On random graphs the algorithm must agree with exhaustive search. The program also counts the guesses YY examined over all compression steps, which the analysis bounds by n⋅2k+1n \cdot 2^{k+1}.

python · try it yourself
import random
from itertools import combinations

def compress(adj, verts, k, Z):
    guesses = 0
    for r in range(len(Z) + 1):
        for Y in combinations(sorted(Z), r):
            guesses += 1
            W = set(Z) - set(Y)
            if any(b in adj[a] for a in W for b in W):
                continue
            X = set(Y) | {b for a in W for b in adj[a] if b in verts}
            if len(X) <= k:
                return X, guesses
    return None, guesses

def ic(adj, n, k):
    X, verts, total = set(), set(), 0
    for v in range(n):
        verts.add(v)
        X = X | {v}
        if len(X) > k:
            X, g = compress(adj, verts, k, X)
            total += g
            if X is None:
                return None, total
    return X, total

def opt(adj, n):
    E = [(a, b) for a in adj for b in adj[a] if a < b]
    for s in range(n + 1):
        for S in combinations(range(n), s):
            if all(a in S or b in S for a, b in E):
                return s

print(" n  OPT  IC(k=OPT)  IC(k=OPT-1)  guesses  bound n*2^(k+1)")
for seed in range(5):
    n = 14
    rng = random.Random(seed)
    adj = {v: set() for v in range(n)}
    for a, b in combinations(range(n), 2):
        if rng.random() < 0.2:
            adj[a].add(b); adj[b].add(a)
    o = opt(adj, n)
    X, g = ic(adj, n, o)
    Xn, _ = ic(adj, n, o - 1)
    print(f"{n} {o:4} {len(X):10} {str(Xn):>12} {g:8} {n * 2 ** (o + 1):16}")
 n  OPT  IC(k=OPT)  IC(k=OPT-1)  guesses  bound n*2^(k+1)
14    4          4         None       28              448
14    6          6         None       96             1792
14    5          5         None       41              896
14    6          6         None      208             1792
14    7          7         None       80             3584

In C++

Iterative compression for vertex cover with vertex sets as 64-bit masks. A guess YY is a submask of ZZ, enumerated with the standard sub = (sub - 1) & Z loop.

cpp · try it yourself
#include <bit>
#include <cstdint>
#include <cstdio>
#include <vector>

int main() {
    const int n = 24;
    std::vector<uint64_t> adj(n, 0);
    unsigned s = 3;
    for (int a = 0; a < n; a++)
        for (int b = a + 1; b < n; b++) {
            s = s * 1103515245u + 12345u;
            if ((s >> 16) % 100 < 12) { adj[a] |= 1ULL << b; adj[b] |= 1ULL << a; }
        }
    for (int k = 8;; k++) {
        uint64_t X = 0, verts = 0;
        long guesses = 0;
        bool ok = true;
        for (int v = 0; v < n && ok; v++) {
            verts |= 1ULL << v;
            uint64_t Z = X | (1ULL << v);
            if (std::popcount(Z) <= k) { X = Z; continue; }
            ok = false;
            for (uint64_t Y = Z;; Y = (Y - 1) & Z) {         // all subsets of Z
                guesses++;
                uint64_t W = Z & ~Y, NW = 0;
                bool indep = true;
                for (uint64_t w = W; w; w &= w - 1) {
                    int a = std::countr_zero(w);
                    if (adj[a] & W) indep = false;
                    NW |= adj[a] & verts;
                }
                uint64_t cand = Y | NW;
                if (indep && std::popcount(cand) <= k) { X = cand; ok = true; break; }
                if (Y == 0) break;
            }
        }
        std::printf("k = %2d: %s after %ld guesses\n", k, ok ? "cover found" : "no cover  ", guesses);
        if (ok) {
            std::printf("cover:");
            for (int v = 0; v < n; v++) if (X >> v & 1) std::printf(" %d", v);
            std::printf("\n");
            break;
        }
    }
}
k =  8: no cover   after 941 guesses
k =  9: no cover   after 2479 guesses
k = 10: cover found after 5250 guesses
cover: 0 1 2 7 9 10 12 14 16 17

Odd cycle transversal and feedback vertex set

The scheme pays off where the disjoint problem is not trivial but still polynomial or FPT.

Odd cycle transversal (sketch). Given an OCT ZZ of size k+1k + 1, G−ZG - Z is bipartite. Guess Y=X∩ZY = X \cap Z and, for the kept vertices W=Z∖YW = Z \setminus Y, guess which side of the final bipartition each one lands on: 3k+13^{k+1} guesses in total. Each kept vertex now forces its neighbours in G−ZG - Z toward the opposite side. Deciding which vertices of G−ZG - Z to delete so that all these forced sides are consistent turns into a minimum vertex cut between two terminal sets in an auxiliary graph, computable by max-flow (Max-Flow Min-Cut) in polynomial time. The result is an O(3k⋅kmn)O(3^k \cdot k m n) algorithm (Reed, Smith and Vetta, 2004), the first proof that odd cycle transversal is FPT.

Feedback vertex set (stated). In the disjoint version, G−ZG - Z is a forest and the solution must avoid W=Z∖YW = Z \setminus Y. Branching on forest vertices with a measure that counts both kk and the number of components of G[W]G[W] gives O∗(5k)O^*(5^k) for compression, hence a deterministic O∗(5k)O^*(5^k) algorithm (Chen, Fomin, Liu, Lu and Villanger, 2008). Refinements of the same approach lowered the base below 4.

Iterative compression has also settled problems open for years, such as directed feedback vertex set (Chen, Liu, Lu, O'Sullivan and Razgon, 2008). The common shape: the old solution of size k+1k + 1 is used as a small "window" into the graph that turns a global problem into a local one, at a cost of 2O(k)2^{O(k)} guesses.

Test yourself

Why may iterative compression stop with NO as soon as one compression step fails?

  1. Because later vertices only make the problem easier
  2. Because the problem is hereditary: a solution of size kk for GG would restrict to one for every induced subgraph GiG_i
  3. Because the order of the vertices is random
  4. Because compression is exact only on the last step

In compression for vertex cover, a guess Y⊆ZY \subseteq Z fixes X∩Z=YX \cap Z = Y. What is the best cover for that guess?

  1. ZZ itself
  2. Y∪N(Z∖Y)Y \cup N(Z \setminus Y), provided Z∖YZ \setminus Y is independent
  3. YY alone
  4. V∖YV \setminus Y

How many guesses does the compression step for odd cycle transversal make, and why?

  1. 2k+12^{k+1}: only which vertices of ZZ to keep
  2. 3k+13^{k+1}: each vertex of ZZ is deleted, or kept on one of the two sides
  3. k+1k + 1
  4. (k+1)!(k+1)!