-3

The following gives a practical example:

Let's say for m = 4:

// the sets for reuniting
Set1 = { 5 , 1 , 2 }
Set2 = { 2 , 6 , 3 }
Set3 = { 7 , 8 , 4 }
Set4 = { 4 , 9 , 10}

// the set I need to form
Set m+1: Set5 = { 1 , 2 , 3 , 4 }

I have to find a set of indexes e.g. A = { 1, 2, 3 } so that U (Seti) includes Set5, where i is part of A. The cardinal of A must be minimal.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256

2 Answers2

2

If I understood your question correctly,

this is the set cover problem, which is NP hard.

As a consequence, there is no algorithm which is both optimal and greedy. Check the article which shows a greedy suboptimal approach.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • Yes, that is the problem. Thanks for the link, but that greedy algorithm seems to have a pretty big complexity, I was hoping for an innovative ideea for something faster. – user1064088 Dec 19 '11 at 11:56
0

if i understood the problem correctly, here's pseudo code that returns the indexes of the sets that cover set5:

setTmp = set5
A = {}
foreach i:
  if (seti intersect setTmp) is not empty then
    setTmp = setTmp  \ setI
    A.add(i)
return A

notice that it's a greedy approach and doesn't guarantee A being minimal

yurib
  • 8,043
  • 3
  • 30
  • 55