Branching Vectors and a Faster Vertex Cover
The bound of Bounded Search Trees for Vertex Cover comes from two branches that each lower by only one. If some branch lowers by more, the tree is smaller. This lesson develops the arithmetic for such unequal branchings and uses it to bring vertex cover down to with one extra observation.
Branching vectors and branching numbers
Suppose every node of a search tree with parameter branches into children with parameters , where all . The vector is the branching vector. The number of leaves satisfies
Lemma. , where is the unique positive root of
is the branching number of the vector.
Proof. The right-hand side is strictly decreasing in , goes to near and to 0 as , so the root exists and is unique. By induction, for (base cases are ): .
Some values, computed by bisection:
def branching_number(vec):
lo, hi = 1.0, 10.0
for _ in range(100):
mid = (lo + hi) / 2
if sum(mid ** -t for t in vec) > 1:
lo = mid
else:
hi = mid
return hi
for vec in [(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (1, 1, 1), (1, 2, 2), (3, 3, 3)]:
print(f"{str(vec):10} -> {branching_number(vec):.4f}")(1, 1) -> 2.0000
(1, 2) -> 1.6180
(1, 3) -> 1.4656
(1, 4) -> 1.3803
(2, 2) -> 1.4142
(2, 3) -> 1.3247
(1, 1, 1) -> 3.0000
(1, 2, 2) -> 2.0000
(3, 3, 3) -> 1.4422
The vector gives the golden ratio ; gives . A balanced vector is better than an unbalanced one with the same sum: gives , below .
Branching on a high-degree vertex
For a vertex , every vertex cover either contains , or does not; in the second case it must contain all neighbours of , since each edge needs an endpoint. So we may branch:
VC-DEGREE(G, k)
0 if k < 0: return NO // line 7 may overshoot the budget
1 if G has no edges: return YES
2 if k = 0: return NO
3 if every vertex has degree <= 2:
4 return YES if the exact cover of the paths and cycles has size <= k
5 pick a vertex v of degree d >= 3
6 if VC-DEGREE(G - v, k - 1) = YES: return YES
7 return VC-DEGREE(G - N[v], k - d) // N(v) goes into the coverLine 4 is polynomial: a graph of maximum degree 2 is a disjoint union of paths and cycles, a path on vertices needs cover vertices and a cycle on vertices needs . Line 7 removes as well, since all its edges are covered. The branching vector is with , and is never worse than , so the tree has leaves and the algorithm runs in time.
import random
from itertools import combinations
def random_graph(n, p, seed):
rng = random.Random(seed)
adj = {v: set() for v in range(n)}
for u in range(n):
for v in range(u + 1, n):
if rng.random() < p:
adj[u].add(v); adj[v].add(u)
return adj
def delete(adj, S):
return {v: nb - S for v, nb in adj.items() if v not in S}
def cover_max_deg2(adj):
seen, total = set(), 0
for s in adj:
if s in seen or not adj[s]:
continue
comp, stack = [], [s] # collect the component
seen.add(s)
while stack:
x = stack.pop(); comp.append(x)
for y in adj[x]:
if y not in seen:
seen.add(y); stack.append(y)
edges = sum(len(adj[x]) for x in comp) // 2
total += (len(comp) + 1) // 2 if edges == len(comp) else len(comp) // 2
return total
def plain(adj, k, st):
st[0] += 1
e = next(((u, v) for u in adj for v in adj[u]), None)
if e is None:
return True
if k <= 0:
return False
return plain(delete(adj, {e[0]}), k - 1, st) or plain(delete(adj, {e[1]}), k - 1, st)
def by_degree(adj, k, st):
st[0] += 1
if k < 0:
return False
if all(not nb for nb in adj.values()):
return True
if k <= 0:
return False
v = max(adj, key=lambda x: (len(adj[x]), -x))
if len(adj[v]) <= 2:
return cover_max_deg2(adj) <= k
return by_degree(delete(adj, {v}), k - 1, st) or by_degree(delete(adj, adj[v] | {v}), k - len(adj[v]), st)
def brute_opt(adj):
E = [(u, v) for u in adj for v in adj[u] if u < v]
for s in range(len(adj) + 1):
for S in combinations(adj, s):
S = set(S)
if all(u in S or v in S for u, v in E):
return s
print(" n OPT nodes(edge branching) nodes(degree branching) agree")
for seed in range(5):
G = random_graph(16, 0.25, seed)
opt = brute_opt(G)
a, b = [0], [0]
ra = [plain(G, k, a) for k in (opt - 1, opt)]
rb = [by_degree(G, k, b) for k in (opt - 1, opt)]
print(f"16 {opt:4} {a[0]:22} {b[0]:24} {ra == rb == [False, True]}") n OPT nodes(edge branching) nodes(degree branching) agree
16 7 363 18 True
16 9 606 21 True
16 9 626 20 True
16 8 751 16 True
16 9 1023 25 True
Each row runs both algorithms for (a NO instance, where the whole tree is explored) and , and checks both answers against brute force.
In C++
The degree-branching algorithm with adjacency bitmasks (up to 64 vertices): is one mask operation, the degree of is a population count, and the max-degree-2 base case walks each component.
#include <bit>
#include <cstdint>
#include <cstdio>
#include <vector>
int n;
std::vector<uint64_t> adj;
long nodes = 0;
int deg(int v, uint64_t alive) { return std::popcount(adj[v] & alive); }
int cover_deg2(uint64_t alive) {
int total = 0;
uint64_t seen = 0;
for (int s = 0; s < n; s++) {
if (!(alive >> s & 1) || (seen >> s & 1) || deg(s, alive) == 0) continue;
uint64_t comp = 0, frontier = 1ULL << s;
while (frontier) {
int x = std::countr_zero(frontier);
frontier &= frontier - 1;
if (comp >> x & 1) continue;
comp |= 1ULL << x;
frontier |= adj[x] & alive & ~comp;
}
seen |= comp;
int vs = std::popcount(comp), es = 0;
for (uint64_t c = comp; c; c &= c - 1) es += deg(std::countr_zero(c), alive);
es /= 2;
total += (es == vs) ? (vs + 1) / 2 : vs / 2;
}
return total;
}
bool solve(uint64_t alive, int k) {
nodes++;
if (k < 0) return false;
int best = -1, bd = 0;
for (int v = 0; v < n; v++)
if ((alive >> v & 1) && deg(v, alive) > bd) { bd = deg(v, alive); best = v; }
if (bd == 0) return true;
if (k <= 0) return false;
if (bd <= 2) return cover_deg2(alive) <= k;
if (solve(alive & ~(1ULL << best), k - 1)) return true;
return solve(alive & ~(adj[best] | (1ULL << best)), k - bd);
}
int main() {
n = 40;
adj.assign(n, 0);
unsigned s = 5;
for (int u = 0; u < n; u++)
for (int v = u + 1; v < n; v++) {
s = s * 1103515245u + 12345u;
if ((s >> 16) % 100 < 10) { adj[u] |= 1ULL << v; adj[v] |= 1ULL << u; }
}
uint64_t all = (n == 64) ? ~0ULL : ((1ULL << n) - 1);
long total = 0;
for (int k = 0;; k++) {
nodes = 0;
bool ok = solve(all, k);
total += nodes;
if (ok) { std::printf("minimum cover %d, %ld nodes over all k, last call %ld\n", k, total, nodes); break; }
}
}minimum cover 23, 4040 nodes over all k, last call 17
How far this goes
Refining the case analysis (branching differently on vertices of degree 3, 4 and 5, using reduction rules for degree-1 and degree-2 vertices, and measuring progress by more than ) has lowered the base steadily:
| Bound | Authors |
|---|---|
| folklore | |
| branching on a vertex of degree at least 3, as above | |
| Chen, Kanj and Jia (2001) | |
| Chen, Kanj and Xia (2010) |
The last bound combines branching with the kernel of The Nemhauser-Trotter LP Kernel, so the exponential part runs on a graph with at most vertices. Results of this kind are theorems about worst-case trees. On real instances, good reduction rules usually matter more than a smaller base.
Note: Branching numbers multiply cleanly with polynomial factors only when every node does polynomial work. A branching step that itself takes exponential time, such as trying all subsets of a neighbourhood, needs its own accounting.
Test yourself
What is the branching number of the vector ?
- 2
- About 1.4656, the positive root of
- About 1.618
- 3
When VC-DEGREE does not put in the cover, why may it put all of in?
- Because is an independent set
- Because each edge must be covered and is not in the cover, so every neighbour must be
- Because neighbours have higher degree
- Because it is a heuristic
Why does VC-DEGREE need a separate base case for graphs of maximum degree at most 2?
- Because such graphs have no vertex cover
- Because branching on a degree-2 vertex gives vector , which would raise the base to 1.618; and such graphs are paths and cycles, solvable exactly in polynomial time
- Because the recursion would not terminate
- Because becomes negative
Which vector gives the smaller search tree: or ?
- , with branching number against 1.4656
- They are equal because the sums are equal
- It depends on