TExcelTAD
Home › Parameterized & Fine-Grained Complexity › Cluster Editing and Feedback Vertex Set by Branching

Cluster Editing and Feedback Vertex Set by Branching

Vertex cover branches on an edge, a two-element obstruction. Many problems have a different small obstruction that every solution must destroy, and the same recipe applies: find one, branch over the ways of destroying it. This lesson does it for an editing problem with a three-way branch and then for feedback vertex set, where the obstruction (a cycle) can be long and the branching needs a lemma.

Cluster editing

A cluster graph is a disjoint union of cliques. In data analysis, vertices are items and edges say "similar"; noisy similarity data is almost a cluster graph, and the fewest corrections that make it one give a clustering.

CLUSTER EDITING. Given a graph GG and kk, can we add or delete at most kk edges so that the result is a cluster graph?

The problem is NP-hard (Křivánek and Morávek, 1986; Shamir, Sharan and Tsur, 2004). The parameterized algorithm rests on one characterization.

Lemma. A graph is a cluster graph if and only if it has no induced P3P_3: no three vertices u,v,wu, v, w with uv,vw∈Euv, vw \in E and uw∉Euw \notin E.

Proof. In a disjoint union of cliques, uvuv and vwvw put u,v,wu, v, w in the same clique, so uwuw is an edge. Conversely, if there is no induced P3P_3, adjacency plus equality is transitive, hence an equivalence relation, and its classes are cliques with no edges between them. □\square

An induced P3P_3 (u,v,w)(u, v, w) is destroyed only by deleting uvuv, deleting vwvw or adding uwuw; edits elsewhere leave these three pairs as they were. So branch three ways, each spending one edit:

text
CLUSTER-EDIT(G, k)
1  find an induced P3 (u, v, w);  if none: return YES
2  if k = 0: return NO
3  for each edit in [delete uv, delete vw, add uw]
4      if CLUSTER-EDIT(G with that edit, k - 1) = YES: return YES
5  return NO

The branching vector is (1,1,1)(1, 1, 1), so at most 3k3^k leaves; finding a P3P_3 takes O(n3)O(n^3) time naively, for O(3kn3)O(3^k n^3) in total (Gramm, Guo, Hüffner and Niedermeier, 2005, who also improved the base by a finer case analysis). The program checks the answers against exhaustive search over all sets of at most kk toggled pairs on small random graphs.

python · try it yourself
import random
from itertools import combinations

def random_graph(n, p, seed):
    rng = random.Random(seed)
    return {frozenset(e) for e in combinations(range(n), 2) if rng.random() < p}

def find_p3(n, E):
    for v in range(n):
        for u, w in combinations(range(n), 2):
            if v not in (u, w) and frozenset((u, v)) in E and frozenset((v, w)) in E and frozenset((u, w)) not in E:
                return u, v, w
    return None

def branch(n, E, k, st):
    st[0] += 1
    p = find_p3(n, E)
    if p is None:
        return True
    if k == 0:
        return False
    u, v, w = p
    for e in (frozenset((u, v)), frozenset((v, w)), frozenset((u, w))):
        if branch(n, E ^ {e}, k - 1, st):           # ^ toggles the pair
            return True
    return False

def brute(n, E, k):
    pairs = [frozenset(e) for e in combinations(range(n), 2)]
    tried = 0
    for size in range(k + 1):
        for T in combinations(pairs, size):
            tried += 1
            if find_p3(n, E ^ set(T)) is None:
                return size, tried
    return None, tried

print("n  |E|  min edits  nodes at k=OPT-1  nodes at k=OPT  brute-force edit sets")
for seed in range(5):
    n = 7
    E = random_graph(n, 0.45, seed)
    opt, tried = brute(n, E, 6)
    a, b = [0], [0]
    r1, r2 = branch(n, E, opt - 1, a), branch(n, E, opt, b)
    assert (r1, r2) == (False, True)
    print(f"{n} {len(E):4} {opt:10} {a[0]:16} {b[0]:15} {tried:22}")
n  |E|  min edits  nodes at k=OPT-1  nodes at k=OPT  brute-force edit sets
7    7          3               13              22                   1021
7   11          4               40              67                   6013
7    9          4               40               7                   1980
7    7          4               40               5                   1783
7   13          5              121              37                   9129

The search tree for a NO instance with k=OPT−1k = \text{OPT} - 1 stays within 3k+1−12\frac{3^{k+1} - 1}{2} nodes, while brute force must try every set of at most OPT pairs out of (72)=21\binom{7}{2} = 21.

In C++

The same branching with the adjacency matrix edited in place and restored on return.

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

int n;
std::vector<std::vector<int>> a;
long nodes = 0;

bool find_p3(int& u, int& v, int& w) {
    for (v = 0; v < n; v++)
        for (u = 0; u < n; u++)
            for (w = u + 1; w < n; w++)
                if (u != v && w != v && a[u][v] && a[v][w] && !a[u][w]) return true;
    return false;
}

bool solve(int k) {
    nodes++;
    int u, v, w;
    if (!find_p3(u, v, w)) return true;
    if (k == 0) return false;
    int pairs[3][2] = {{u, v}, {v, w}, {u, w}};
    for (auto& p : pairs) {
        int x = p[0], y = p[1];
        a[x][y] ^= 1; a[y][x] ^= 1;
        bool ok = solve(k - 1);
        a[x][y] ^= 1; a[y][x] ^= 1;
        if (ok) return true;
    }
    return false;
}

int main() {
    n = 12;
    a.assign(n, std::vector<int>(n, 0));
    // three planted clusters {0..3}, {4..7}, {8..11}, then noise
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (i != j && i / 4 == j / 4) a[i][j] = 1;
    int noise[][2] = {{0, 5}, {3, 9}, {6, 7}, {10, 11}, {2, 8}};
    for (auto& e : noise) { a[e[0]][e[1]] ^= 1; a[e[1]][e[0]] ^= 1; }
    long total = 0;
    for (int k = 0;; k++) {
        nodes = 0;
        bool ok = solve(k);
        total += nodes;
        std::printf("k = %d: %s (%ld nodes)\n", k, ok ? "YES" : "NO", nodes);
        if (ok) break;
    }
    std::printf("total search-tree nodes: %ld\n", total);
}
k = 0: NO (1 nodes)
k = 1: NO (4 nodes)
k = 2: NO (13 nodes)
k = 3: NO (40 nodes)
k = 4: NO (121 nodes)
k = 5: YES (190 nodes)
total search-tree nodes: 369

Five noise edits were applied to three clean clusters, so at most 5 edits suffice; the search confirms the minimum and shows the tree growing roughly threefold per unit of kk while the answer is NO.

Better bounds (stated): by branching more carefully the base drops to 1.62 (Böcker, 2012), and the problem has a kernel with at most 2k2k vertices (Chen and Meng, 2012). Kernels are the subject of the next section.

Feedback vertex set

A feedback vertex set (FVS) of a graph is a set XX of vertices whose removal leaves a forest. FEEDBACK VERTEX SET asks for one of size at most kk. The obstruction is a cycle, and cycles can be long, so "branch on the vertices of a cycle" gives no bound in terms of kk. Two ingredients fix this.

Reduction rules. Work with multigraphs (parallel edges and loops allowed).

  1. A vertex with a loop must be in XX: delete it and lower kk.
  2. A vertex of degree at most 1 is on no cycle: delete it.
  3. A vertex vv of degree 2 with neighbours u,wu, w can be bypassed: delete vv and add an edge uwuw (possibly a parallel edge, or a loop if u=wu = w). Any cycle through vv also passes through uu and ww, so some optimal solution avoids vv.
  4. If an edge has multiplicity more than 2, reduce it to 2 (a double edge is already a cycle of length 2).

After the rules, every vertex has degree at least 3.

Lemma (stated; see Cygan et al., Parameterized Algorithms, 2015, Chapter 3). If GG has minimum degree at least 3, then every feedback vertex set of size at most kk contains one of the 3k3k vertices of largest degree.

The idea of the proof is a degree count: a forest on the remaining vertices has fewer edges than vertices, and minimum degree 3 forces many edges to touch XX; if XX avoided the 3k3k highest-degree vertices, the vertices of XX could not carry that many edges.

So branch into 3k3k choices, each putting one vertex into XX and lowering kk, then reduce again. The tree has at most (3k)k(3k)^k leaves, giving an O∗((3k)k)O^*((3k)^k) algorithm: FPT, but with f(k)=(3k)k=2O(klog⁡k)f(k) = (3k)^k = 2^{O(k \log k)}. Single-exponential algorithms followed: randomized O∗(4k)O^*(4^k) by choosing a random edge and a random endpoint (Becker, Bar-Yehuda and Geiger, 2000), and deterministic O∗(ck)O^*(c^k) with constant cc via iterative compression, the technique of the next lesson (Iterative Compression).

Test yourself

Why is the cluster editing search tree bounded by 3k3^k leaves?

  1. Because every vertex has degree at most 3
  2. Because an induced P3P_3 can only be destroyed by one of three edits on its own pairs, and each branch spends one edit
  3. Because there are at most 3 clusters
  4. Because the graph has 3k3k vertices

Which characterization of cluster graphs does the algorithm use?

  1. No triangles
  2. No induced path on three vertices
  3. Bipartite
  4. Every vertex has the same degree

Why can't feedback vertex set branch directly on the vertices of an arbitrary cycle?

  1. Cycles may be long, so the branching factor would not be bounded by a function of kk
  2. Cycles never intersect the solution
  3. Because FVS is not in NP
  4. Because the graph might be a tree

What does bypassing a degree-2 vertex vv with neighbours uu and ww do?

  1. Puts vv into the solution
  2. Deletes vv and adds an edge uwuw, keeping every cycle through vv as a cycle through uu and ww
  3. Deletes uu and ww
  4. Contracts the whole cycle into one vertex