Search for overlapping sets

I am writing Digital Fountain in C #. Part of this system creates integers for me, I need to find combinations of sets that create can leave me with a set of only one element. What is the fastest way to do this?

Set A: 1,2,3,4,5,6
Set B: 1,2,3,4,6
Set C: 1,2,3
Set D: 5,6

Solutions:
A - B => 5
A - (C + D) => 4

I do not need to find all the combinations, enough to find as many unique numbers as possible. This may be possible to use to create a more efficient algorithm.

An important point that I forgot to mention: I don’t know in advance how many sets there are, instead I add them one by one and each time I have to determine if I will find every number that I need. Thus, the algorithm should be something that can be run in stages as new sets are added.

Nb. Decisions in C # get bonus points;)

+3
1

, (http://en.wikipedia.org/wiki/Set_cover_problem).

[] :

1. sort sets by size descending
2.
foreach set in sets do:
  uncovered = set.size
  while uncovered > 1
    current_set = the biggest set that covers no more than (uncovered - 1) and was not used before to cover set
    uncovered = uncovered - covered_by_set(set)
    collect current_set to some array
  end
end

  • foreach
  • ( set cover), , [1,3,4], SCV = 2: [1,3], [1,4], [3,4].
  • , , - ( , , 1), (, , )
+1

Source: https://habr.com/ru/post/1767860/


All Articles