Algorithms and Complexity – DP Hitting set

Given:
A={a_1,a_2,\dots,a_n}
B_1, B_2,\dots, B_m that all contain elements from A means subset of A, |B_i| \leq c
Subset H\subseteq A is a hitting set if it contains an element from all B_i's
Size k = |H|

Solve:

Branching-HS(A, (B1, …,Bm), k)
if k = o: 		//base case
	if Bi = original Bi for some i:
		return “no HS”
	else return empty set
else:
	choose some Bi
	for u ∈ Bi
		Brahching-HS(A-u, {Bi-u | i=1, …, m}, k-1)
	if all recursive
		return “no HS”, then return “no HS”
	else:
            choose some u where u ∈ Bi worked,
            add u to the result from that, call and return.

Running Time:

  • {Bi-u | i=1 to m} takes O(m)
  • T(n, m, k) = c \times T(n-1, m, k-1) + O(cm)
    • there are c amout of u in B_i, so this runs in c times
    • Subset has c elements, A have n elements, c\leq n so O(cm)=O(nm)

Rerolling above gives overall running time O(c^knm).

One Comment

  1. Luella

    thank you

Leave a Comment