This feels quite a bit like an odd mix of systems of distinct representatives and block designs, although this exact problem isn't coming to mind as a particular construction in any of these combinatorial contexts. It would probably help to pull out a book about matroids too -- that's not my forte either.
It's important to note that all of your sets will be transversals of your set system, at least, that's how I'm reading the question. Otherwise, the union of these sets will trivially contain all the pairs... I'm quite sure that's not what you want!
I think it will be easier if we assume your set system is as follows:
L[1]={x[1,1], x[1,2], x[1,3], ... , x[1,n[1]]}
L[2]={x[2,1], x[2,2], x[2,3], ... , x[2,n[2]]}
...
L[k]={x[k,1], x[k,2], x[k,3], ... , x[k,n[k]]}
It is important to note, then, that such a configuration depends only on ${n[1],...,n[k]}$. If you have some other lists that you want to apply this to, that's fine, you can just pick of the x[i,j]
in each transversal as representing the $j^{\mathrm{th}}$ element of the $i^{\mathrm{th}}$ list.
We also may as well assume each n[i]
is at least 2. If it's just 1, then add x[1,n[i]]
to every transversal in the set system minus those. We can also assume the n[i]
are increasing.
My approach to the problem will be induction
First of all, what if $k=1$? Then you just return the set of single-element sets:
{{x[1,1]},{x[1,2]},...,{x[1,n[1]]}}
Now, if $k=2$ you literally need every combination, don't you?
I don't have time right now to elaborate or post much code, but if you let T
be a set of transverals that covers your system, and say T-i
is that set of transversals, each missing the element from set L[i]
.
Now, it's easy enough to get a set T
of size n[k]
. Let S[i]
be each set of T-i
with every possible combination of elements from L[i]
. That's at most n[k]^2
sets, and the union of all of these S[i]
gives you what you want with at most k*n[k]^2
sets. In fact, you can skip the last one, giving you (k-1)*n[k]^2
, although that's not really an improvement -- linear is linear.
As I mentioned, I don't really have much time to give this more thought, it's interesting, but (unless I've done something wrong in my rush to say something useful in the time I have for MMASE today) it's quadratic in n[k]
and linear in k
, worst case.
This would produce, for the given example:
S = { { A, B }, { C, D, E, F }, { X, Y } }
T = { { A, C, X }, { B, D, Y }, { A, E, X }, { B, F, Y } }
T-1 = { { C, X }, { D, Y }, { E, X }, { F, Y } }
T-2 = { { A, X }, { B, Y }, { A, X }, { B, Y } }
T-3 = { { A, C }, { B, D }, { A, E }, { B, F } }
S[1] = { { A, C, X }, { B, C, X },
{ A, D, Y }, { B, D, Y },
{ A, E, X }, { B, E, X },
{ A, F, Y }, { B, F, Y } }
S[2] = { { A, C, X }, { A, D, X }, { A, E, X }, { A, F, X },
{ B, C, Y }, { B, D, Y }, { B, E, Y }, { B, F, Y },
{ A, C, X }, { A, D, X }, { A, E, X }, { A, F, X },
{ B, C, Y }, { B, D, Y }, { B, E, Y }, { B, F, Y } }
Now in this case, you get way too many -- and in general, this is not an especially efficient way of doing it, but I'm fairly sure this bound is better than n1*n2*n3*...*nk
for whatever purposes. It wouldn't be particularly hard to code, but I don't have the time.
This could probably be faster/more efficient by making the judicious choice of a different covering set of transversals for each i. That and throwing away duplicates (throwing away duplicates, by the way, seems to give you 12 in this case).
This is assuming no use of anything even remotely intelligent like deleting duplicates in T-2
. This could be optimized and I'm not of any particular belief that the bound k*n[k]^2
is tight in any way. Consider this answer an extended comment more than an answer, i just want to get this bound out there for everyone to chew on.
Belisarius is asking if there are m
(my k
) groups of 2, what is it, and in this case you might get lazy and call them {x1,x1}
through {xk,yk}
. The scheme I propose, with duplicates knocked out, I think is going to give you the following:
{x1,x2,x3,...,x(k-1),xk}
{y1,y2,y3,...,y(k-1),yk}
{y1,x2,x3,...,x(k-1),xk}
{x1,y2,y3,...,y(k-1),yk}
{x1,y2,x3,...,x(k-1),xk}
{y1,x2,y3,...,y(k-1),yk}
{x1,x2,y3,...,x(k-1),xk}
{y1,y2,x3,...,x(k-1),yk}
...
...
{x1,x2,x3,...,y(k-1),xk}
{y1,y2,y3,...,x(k-1),yk}
Obviously this list is incredibly redundant! Probably because all the n[i]
are 2, it is exaggeratedly inefficient.
{{A, C, X}, {B, C, Y}, {A, D, Y}, {B, D, X}, {A, E, X}, {B, E, Y}, {A, F, Y}, {B, F, X}}
a shorter paths list sharing the same property? $\endgroup$