Question

Given a bunch of sets of people (similar to):

[p1,p2,p3]
[p2,p3]
[p1]
[p1]

Select 1 from each set, trying to minimize the maximum number of times any one person is selected.

For the sets above, the max number of times a given person MUST be selected is 2.

I'm struggling to get an algorithm for this. I don't think it can be done with a greedy algorithm, more thinking along the lines of a dynamic programming solution.

Any hints on how to go about this? Or do any of you know any good websites about this stuff that I could have a look at?

Was it helpful?

Solution

This is neither dynamic nor greedy. Let's look at a different problem first -- can it be done by selecting every person at most once?

You have P people and S sets. Create a graph with S+P vertices, representing sets and people. There is an edge between person pi and set si iff pi is an element of si. This is a bipartite graph and the decision version of your problem is then equivalent to testing whether the maximum cardinality matching in that graph has size S.

As detailed on that page, this problem can be solved by using a maximum flow algorithm (note: if you don't know what I'm talking about, then take your time to read it now, as you won't understand the rest otherwise): first create a super-source, add an edge linking it to all people with capacity 1 (representing that each person may only be used once), then create a super-sink and add edges linking every set to that sink with capacity 1 (representing that each set may only be used once) and run a suitable max-flow algorithm between source and sink.

Now, let's consider a slightly different problem: can it be done by selecting every person at most k times?

If you paid attention to the remarks in the last paragraph, you should know the answer: just change the capacity of the edges leaving the super-source to indicate that each person may be used more than once in this case.

Therefore, you now have an algorithm to solve the decision problem in which people are selected at most k times. It's easy to see that if you can do it with k, then you can also do it with any value greater than k, that is, it's a monotonic function. Therefore, you can run a binary search on the decision version of the problem, looking for the smallest k possible that still works.

Note: You could also get rid of the binary search by testing each value of k sequentially, and augmenting the residual network obtained in the last run instead of starting from scratch. However, I decided to explain the binary search version as it's conceptually simpler.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top