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 and , can we add or delete at most 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 : no three vertices with and .
Proof. In a disjoint union of cliques, and put in the same clique, so is an edge. Conversely, if there is no induced , adjacency plus equality is transitive, hence an equivalence relation, and its classes are cliques with no edges between them.
An induced is destroyed only by deleting , deleting or adding ; edits elsewhere leave these three pairs as they were. So branch three ways, each spending one edit:
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 NOThe branching vector is , so at most leaves; finding a takes time naively, for 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 toggled pairs on small random graphs.
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 stays within nodes, while brute force must try every set of at most OPT pairs out of .
In C++
The same branching with the adjacency matrix edited in place and restored on return.
#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 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 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 of vertices whose removal leaves a forest. FEEDBACK VERTEX SET asks for one of size at most . The obstruction is a cycle, and cycles can be long, so "branch on the vertices of a cycle" gives no bound in terms of . Two ingredients fix this.
Reduction rules. Work with multigraphs (parallel edges and loops allowed).
- A vertex with a loop must be in : delete it and lower .
- A vertex of degree at most 1 is on no cycle: delete it.
- A vertex of degree 2 with neighbours can be bypassed: delete and add an edge (possibly a parallel edge, or a loop if ). Any cycle through also passes through and , so some optimal solution avoids .
- 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 has minimum degree at least 3, then every feedback vertex set of size at most contains one of the 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 ; if avoided the highest-degree vertices, the vertices of could not carry that many edges.
So branch into choices, each putting one vertex into and lowering , then reduce again. The tree has at most leaves, giving an algorithm: FPT, but with . Single-exponential algorithms followed: randomized by choosing a random edge and a random endpoint (Becker, Bar-Yehuda and Geiger, 2000), and deterministic with constant via iterative compression, the technique of the next lesson (Iterative Compression).
Test yourself
Why is the cluster editing search tree bounded by leaves?
- Because every vertex has degree at most 3
- Because an induced can only be destroyed by one of three edits on its own pairs, and each branch spends one edit
- Because there are at most 3 clusters
- Because the graph has vertices
Which characterization of cluster graphs does the algorithm use?
- No triangles
- No induced path on three vertices
- Bipartite
- Every vertex has the same degree
Why can't feedback vertex set branch directly on the vertices of an arbitrary cycle?
- Cycles may be long, so the branching factor would not be bounded by a function of
- Cycles never intersect the solution
- Because FVS is not in NP
- Because the graph might be a tree
What does bypassing a degree-2 vertex with neighbours and do?
- Puts into the solution
- Deletes and adds an edge , keeping every cycle through as a cycle through and
- Deletes and
- Contracts the whole cycle into one vertex