TExcelTAD
Home › Parameterized & Fine-Grained Complexity › Sunflowers and a Kernel for d-Hitting Set

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. dd-HITTING SET generalizes it: given a family F\mathcal{F} of sets, each of size at most dd, over a universe UU, and an integer kk, is there a set H⊆UH \subseteq U with ∣H∣≤k\lvert H \rvert \le k that meets every set of F\mathcal{F}? For d=3d = 3 it models, for example, picking kk servers so that every triple of replicas has a live one. Branching on the elements of an unhit set gives an O∗(dk)O^*(d^k) 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 pp petals and core YY is a collection of sets S1,…,SpS_1, \ldots, S_p with Si∩Sj=YS_i \cap S_j = Y for all i≠ji \ne j. The petals Si∖YS_i \setminus Y are pairwise disjoint; the core may be empty, in which case the sets themselves are disjoint.

text
          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 3

Sunflower lemma (Erdős and Rado, 1960). If F\mathcal{F} contains more than d! (p−1)dd!\,(p-1)^d sets, each of size exactly dd, then F\mathcal{F} contains a sunflower with pp petals, and one can be found in time polynomial in ∣F∣\lvert \mathcal{F} \rvert for fixed dd.

Proof. Induction on dd. For d=1d = 1, more than p−1p - 1 distinct singletons are a sunflower with empty core. For d≥2d \ge 2, take a maximal collection G\mathcal{G} of pairwise disjoint sets of F\mathcal{F} (greedily). If ∣G∣≥p\lvert \mathcal{G} \rvert \ge p, it is a sunflower with empty core. Otherwise the union WW of G\mathcal{G} has at most d(p−1)d(p-1) elements and, by maximality, meets every set of F\mathcal{F}. Some element w∈Ww \in W lies in more than

d! (p−1)dd(p−1)=(d−1)! (p−1)d−1\frac{d!\,(p-1)^d}{d(p-1)} = (d-1)!\,(p-1)^{d-1}

sets. Remove ww from those sets: they form a family of (d−1)(d-1)-sets to which the induction hypothesis applies, giving a sunflower with pp petals; adding ww back to every set and to the core gives a sunflower in F\mathcal{F}. □\square

Sets of size less than dd are handled by applying the lemma to each size separately.

The kernel

Sunflower rule. If F\mathcal{F} contains a sunflower S1,…,Sk+1S_1, \ldots, S_{k+1} with k+1k + 1 petals and core YY:

  • If Y=∅Y = \emptyset, the k+1k + 1 sets are disjoint and no kk elements can hit them all: answer NO.
  • Otherwise, remove S1,…,Sk+1S_1, \ldots, S_{k+1} from F\mathcal{F} and add YY.

Safety. A hitting set HH with ∣H∣≤k\lvert H \rvert \le k cannot hit all k+1k + 1 disjoint petals, so it hits the core YY; then it also hits every Si⊇YS_i \supseteq Y. Hence hitting sets of size at most kk for the old and new family are the same. □\square

Each application lowers the number of sets by kk, so the rule runs at most ∣F∣\lvert \mathcal{F} \rvert times. When it no longer applies, the lemma says that for each size s≤ds \le d there are at most s! kss!\,k^s sets of that size.

Theorem. dd-HITTING SET has a kernel with at most d⋅d! kdd \cdot d!\,k^d sets, hence O(d2 d! kd)O(d^2 \, d!\,k^d) elements, for every fixed dd (Flum and Grohe, 2006, based on the sunflower lemma).

For d=2d = 2 this is a vertex cover kernel with O(k2)O(k^2) edges, the same order as Buss's kernel. Better kernels with O(kd−1)O(k^{d-1}) elements are known (Abu-Khzam, 2010), and a kernel with O(kd−ε)O(k^{d - \varepsilon}) sets is ruled out unless coNP ⊆\subseteq NP/poly (Dell and van Melkebeek, 2010).

Implementation

The program follows the proof: it finds a sunflower with pp petals among sets of one size, or returns nothing. The kernel then repeatedly replaces sunflowers with k+1k + 1 petals by their cores. It is run on random 3-uniform families with a planted hitting set.

python · try it yourself
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 d⋅d! kd=3⋅6⋅27=486d \cdot d!\,k^d = 3 \cdot 6 \cdot 27 = 486 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 {0,…,14}\{0, \ldots, 14\} for sunflowers with 2 to 7 petals.

cpp · try it yourself
#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 3! (p−1)33!\,(p-1)^3; below that it may still find one, as here, or fail.

Test yourself

What is a sunflower with pp petals?

  1. pp sets with a common element
  2. pp sets whose pairwise intersections are all equal to the same core YY
  3. pp pairwise disjoint sets of size pp
  4. A star graph with pp leaves

Why may a sunflower with k+1k + 1 petals and nonempty core YY be replaced by YY?

  1. Because YY is larger than the petals
  2. Because a hitting set of size at most kk cannot hit k+1k + 1 disjoint petals, so it must hit YY, and then it hits all the sets
  3. Because the sets are duplicates
  4. Because kk decreases

What does the sunflower lemma guarantee?

  1. Every family has a sunflower with pp petals
  2. A family of more than d! (p−1)dd!\,(p-1)^d sets of size dd contains a sunflower with pp petals
  3. Sunflowers can only have empty cores
  4. Every hitting set is a sunflower

What size of kernel does the sunflower rule give for dd-hitting set?

  1. O(k)O(k) sets
  2. O(d! kd)O(d!\,k^d) sets for each size, so O(d⋅d! kd)O(d \cdot d!\,k^d) sets in total
  3. 2k2^k sets
  4. No kernel