Given a collection of non-empty subsets of $\{1,2,\ldots,N\}$ ($N$ not fixed), the problem is to find the smallest non-empty collection of subsets so that the number of distinct elements appearing among the union of subsets is less than or equal to the number of subsets chosen. This seems like an NP-hard problem but I can't prove it. Any help?

  • 1
    $\begingroup$ What have you tried? Where did you get stuck? What's your rationale for believing this to be NP-hard. $\endgroup$ Aug 22, 2014 at 18:00
  • $\begingroup$ @ZeroUltimax I thought about things like set-cover but that would mean finding the minimal number of strings so that all characters appear. I also tried to come up with a relationship to a clique problem but got stuck there too. The reason I believe this is NP-hard is that I've tried to come up with polynomial time algorithms and failed, and also someone posted a similar question on StackOverflow asking for a fast algorithm and all they got was brute force and a reduction to integer programming. $\endgroup$ Aug 22, 2014 at 18:27
  • $\begingroup$ It looks like this question doesn't have anything to do with strings. The order of the letters in each string is irrelevant, so you could treat this as a question about sets. I suggest you edit the question accordingly. What have you tried? Have you tried looking at a list of NP-complete problems that involve sets of sets? $\endgroup$
    – D.W.
    Aug 24, 2014 at 3:19
  • $\begingroup$ @D.W. I modified the question to be about sets per your suggestion. Yes, I looked at questions regarding sets and cliques but got stuck. It looks like someone may have a solution involving clique, I'm still checking it out. $\endgroup$ Aug 25, 2014 at 16:55

2 Answers 2


This is too long for a comment but is not really a full answer.

Let's re-formulate the problem setting slightly as a bipartite graph $G$, with $\{1,2,\ldots,N\} = X$ as one set of vertices and the collection of subsets (say, $Y$) as the other set of vertices, with an edge between $i \in X$ and $J \in Y$ iff $i \in J$. For any set of vertices $W$ in $Y$, define $N(W)$ to be the neighborhood of $W$ in $G$ -- namely, the set of all vertices in $X$ that are adjacent to at least one vertex in $W$.

Then, the problem asks to find a minimal subset $W \subseteq Y$ such that $|N(W)| \leq |W|$. However, if we change the criterion slightly to $|N(W)| \lt |W|$, we find that such a subset exists if and only if there does not exist a matching between $X$ and $Y$ that covers $Y$, for it is exactly equivalent to Hall's Marriage Theorem.

Since such matchings are findable in polynomial time (e.g.: via Hopcroft-Karp), I think this version of the problem should probably be relatively easy but I'd have to do some more work to figure out if and how the standard algorithms for bipartite matching expose these deficient sets and whether or not minimal deficient sets can also be obtained easily. Furthermore, I can't tell right away how much harder the original version of the problem (which allows $|N(W)| = |W|$) is than this modified version.


You can reduce from Clique. Create a set for each vertex, each with n-1 elements corresponding to the n-1 other vertices, with the element for v in set u being equal to the element for u in set v (but not equal to any other element) if {u, v} is an edge, and a unique element otherwise. Then we can choose k strings that together contain k(n-k) + k(k-1)/2 elements if an only if there is a clique of size k. We then only need to add the correct number of one-element sets containing the same element such that the number of sets selected and elements collected is the same.

  • $\begingroup$ This does not work: If you have a one-element set, choosing that set alone will always be an optimal solution. $\endgroup$
    – FrankW
    Aug 25, 2014 at 12:16
  • $\begingroup$ Right, avoiding smaller solutions is a problem. I didn't think about that. $\endgroup$ Aug 25, 2014 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.