I have N sets of values, eg.
- S1 = {A,B,C,D,E}
- S2 = {A,B,C,D,E,F}
- S3 = {A,B}
- S4 = {C,E,F,G,H}
I wish to know is if there is a distinct or unique value in each set of the collection… Ie. is there a ‘path’ through the sets that leaves at least one value in each set that is not in any other..
The answer to the example above would be TRUE as you could have :
B from S1, D from S2, A from S3 and C from S4
A FALSE example would be:
- S1 = {A,B,C}
- S2 = {A}
- S3 = {A,B}
- S4 = {A,C}
As values would need to be duplicated between sets.
As always, I am certain there must be a trivial solution to this problem. Any help would be very gratefully received. Thank you
Clarification
Thanks for the answers so far but I am still slightly confused by this, albeit having what is (I think) a simple requirement. I suspect I made the question sound more confusing than the problem it actually represents.
To clarify, my end goal is to:
- Have a single value from each set.
- This list of new values should be distinct from one another.
- The value picked from each set is relatively arbritrary.
- If a single distinct value cannot be derived from the input sets then the process should return nothing
I have read about Bipartite graphs and maximum flow but I cant quite see the ‘wood from the trees’ Ultimately I need to write some code in .NET to implement this, so some pseudo code would be a really big help, if thats not possible just a simpler example of the relevant algorthm in action would be great.
Create a bipartite graph with ;
Match this graph to the problem statement by making edges as per the sets given in the problem.
The problem reduces to checking if the “maximum (bipartite) matching” between X and Y is equal to N. If the assignment of values needs to known, then print this matching as well.
EDIT (for more explanation)
The edges between the two sets denote the original sets. We need to find edges such that all vertices in X are covered and no 2 edges share a common vertex
Note: Multiple maximum matching may exist