Sunflowers and a Kernel for d-Hitting Set
Vertex cover asks for a set of vertices that meets every edge, and an edge is a set of size 2. -HITTING SET generalizes it: given a family of sets, each of size at most , over a universe , and an integer , is there a set with that meets every set of ? For it models, for example, picking servers so that every triple of replicas has a live one. Branching on the elements of an unhit set gives an algorithm, as in Bounded Search Trees for Vertex Cover. This lesson gives a polynomial kernel, built on a classical lemma from extremal combinatorics.
Sunflowers
A sunflower with petals and core is a collection of sets with for all . The petals are pairwise disjoint; the core may be empty, in which case the sets themselves are disjoint.
petal 1 petal 2
\ {a,b} \ / {c,d}
\ \/
[ core Y = {x} ] S1 = {x,a,b}, S2 = {x,c,d}, S3 = {x,e,f}
/
{e,f} petal 3Sunflower lemma (Erdős and Rado, 1960). If contains more than sets, each of size exactly , then contains a sunflower with petals, and one can be found in time polynomial in for fixed .
Proof. Induction on . For , more than distinct singletons are a sunflower with empty core. For , take a maximal collection of pairwise disjoint sets of (greedily). If , it is a sunflower with empty core. Otherwise the union of has at most elements and, by maximality, meets every set of . Some element lies in more than
sets. Remove from those sets: they form a family of -sets to which the induction hypothesis applies, giving a sunflower with petals; adding back to every set and to the core gives a sunflower in .
Sets of size less than are handled by applying the lemma to each size separately.
The kernel
Sunflower rule. If contains a sunflower with petals and core :
- If , the sets are disjoint and no elements can hit them all: answer NO.
- Otherwise, remove from and add .
Safety. A hitting set with cannot hit all disjoint petals, so it hits the core ; then it also hits every . Hence hitting sets of size at most for the old and new family are the same.
Each application lowers the number of sets by , so the rule runs at most times. When it no longer applies, the lemma says that for each size there are at most sets of that size.
Theorem. -HITTING SET has a kernel with at most sets, hence elements, for every fixed (Flum and Grohe, 2006, based on the sunflower lemma).
For this is a vertex cover kernel with edges, the same order as Buss's kernel. Better kernels with elements are known (Abu-Khzam, 2010), and a kernel with sets is ruled out unless coNP NP/poly (Dell and van Melkebeek, 2010).
Implementation
The program follows the proof: it finds a sunflower with petals among sets of one size, or returns nothing. The kernel then repeatedly replaces sunflowers with petals by their cores. It is run on random 3-uniform families with a planted hitting set.
import random
from itertools import combinations
def find_sunflower(F, p):
"""F: list of frozensets, all of the same size. Returns (core, sets) or None."""
disjoint, used = [], set()
for S in F: # a maximal pairwise disjoint subfamily
if not S & used:
disjoint.append(S)
used |= S
if len(disjoint) == p:
return frozenset(), disjoint
if not F or len(next(iter(F))) == 1:
return None
for w in sorted(used, key=lambda w: -sum(w in S for S in F)):
sub = [S - {w} for S in F if w in S]
r = find_sunflower(sub, p)
if r:
core, sets = r
return core | {w}, [S | {w} for S in sets]
return None
def sunflower_kernel(F, k):
F = set(F)
while True:
for size in sorted({len(S) for S in F}, reverse=True):
r = find_sunflower(sorted((S for S in F if len(S) == size), key=sorted), k + 1)
if r:
core, sets = r
if not core:
return None
F -= set(sets)
F.add(core)
break
else:
return F
def min_hitting(F, U):
for s in range(len(U) + 1):
for H in combinations(U, s):
if all(S & set(H) for S in F):
return s
rng = random.Random(6)
for trial in range(4):
U = list(range(30))
planted = rng.sample(U, 3)
F = set()
while len(F) < 120: # every set contains a planted element
S = frozenset([rng.choice(planted)] + rng.sample(U, 2))
if len(S) == 3:
F.add(S)
k = 3
K = sunflower_kernel(F, k)
sizes = sorted(len(S) for S in K)
elems = sorted(set().union(*K))
print(f"|F| = {len(F)} -> kernel {len(K)} sets of sizes {sizes[0]}..{sizes[-1]} on {len(elems)} elements;"
f" min hitting set: before {min_hitting(F, U)}, after {min_hitting(K, elems)}")|F| = 120 -> kernel 7 sets of sizes 1..3 on 9 elements; min hitting set: before 3, after 3
|F| = 120 -> kernel 16 sets of sizes 1..3 on 12 elements; min hitting set: before 3, after 3
|F| = 120 -> kernel 15 sets of sizes 1..3 on 15 elements; min hitting set: before 3, after 3
|F| = 120 -> kernel 11 sets of sizes 1..3 on 12 elements; min hitting set: before 3, after 3
From 120 sets the kernel keeps a few dozen or fewer, many of them shrunk to cores of size 1 or 2, and the minimum hitting set size is unchanged. The bound is far from tight here; it is a worst case.
In C++
A sunflower search for 3-sets in C++, following the same recursion (sets are sorted vectors). It searches a family of 60 random 3-subsets of for sunflowers with 2 to 7 petals.
#include <algorithm>
#include <cstdio>
#include <vector>
using Set = std::vector<int>;
bool disjoint(const Set& a, const std::vector<bool>& used) {
for (int x : a) if (used[x]) return false;
return true;
}
// returns the sunflower's sets (with the removed elements added back) or an empty vector
std::vector<Set> sunflower(const std::vector<Set>& F, int p, int universe) {
std::vector<Set> pick;
std::vector<bool> used(universe, false);
for (auto& S : F)
if (disjoint(S, used)) { pick.push_back(S); for (int x : S) used[x] = true; if ((int)pick.size() == p) return pick; }
if (F.empty() || F[0].size() == 1) return {};
for (int w = 0; w < universe; w++) {
if (!used[w]) continue;
std::vector<Set> sub;
for (auto& S : F)
if (std::count(S.begin(), S.end(), w)) { Set t; for (int x : S) if (x != w) t.push_back(x); sub.push_back(t); }
auto r = sunflower(sub, p, universe);
if (!r.empty()) { for (auto& S : r) { S.push_back(w); std::sort(S.begin(), S.end()); } return r; }
}
return {};
}
int main() {
const int U = 15;
std::vector<Set> F;
unsigned s = 4;
auto rnd = [&](int m) { s = s * 1103515245u + 12345u; return int((s >> 8) % m); };
while (F.size() < 60) {
Set S = {rnd(U), rnd(U), rnd(U)};
std::sort(S.begin(), S.end());
if (S[0] != S[1] && S[1] != S[2] && std::find(F.begin(), F.end(), S) == F.end()) F.push_back(S);
}
for (int p = 2; p <= 7; p++) {
auto r = sunflower(F, p, U);
if (r.empty()) { std::printf("p = %d: no sunflower found\n", p); continue; }
std::printf("p = %d:", p);
for (auto& S : r) std::printf(" {%d,%d,%d}", S[0], S[1], S[2]);
std::printf("\n");
}
}p = 2: {0,8,13} {2,6,12}
p = 3: {0,8,13} {2,6,12} {4,9,10}
p = 4: {0,8,13} {2,6,12} {4,9,10} {1,11,14}
p = 5: {2,6,12} {1,2,11} {2,3,7} {2,5,10} {2,8,14}
p = 6: {2,6,12} {3,6,13} {1,6,14} {4,6,8} {6,7,11} {5,6,9}
p = 7: no sunflower found
With 15 elements at most 5 sets of size 3 can be disjoint, so sunflowers with more petals must have a nonempty core. The constructive proof only guarantees a sunflower when the family is larger than ; below that it may still find one, as here, or fail.
Test yourself
What is a sunflower with petals?
- sets with a common element
- sets whose pairwise intersections are all equal to the same core
- pairwise disjoint sets of size
- A star graph with leaves
Why may a sunflower with petals and nonempty core be replaced by ?
- Because is larger than the petals
- Because a hitting set of size at most cannot hit disjoint petals, so it must hit , and then it hits all the sets
- Because the sets are duplicates
- Because decreases
What does the sunflower lemma guarantee?
- Every family has a sunflower with petals
- A family of more than sets of size contains a sunflower with petals
- Sunflowers can only have empty cores
- Every hitting set is a sunflower
What size of kernel does the sunflower rule give for -hitting set?
- sets
- sets for each size, so sets in total
- sets
- No kernel