At first I didn’t understand the problem, but I think it can be phrased like so:
There’s some mapping of elements from set A to set B. The mapping is arbitrary, in that it is only defined by an examination of the relation of the elements in the sets. Give an algorithm to ascertain the least number of “rules” necessary to express the given mapping.
There’s a problem with the formulation of the question. I think what he’s looking for is: a valid “rule” is defined as each element from set A maps to the same elements from set B. In other words, they have a common mapping. That is, if:
A => 1
B => 1,2
C => 2
then the rules:
A,B => 1
B,C => 2
are valid. However, if:
A => 1
B => 1,2
C => 3
then at least three rules are needed.
A brute force algorithm that I think will work is to take the element from set A with the greatest out-degree, then see if any other elements from set A have common mappings. If there are multiple mappings that are not the same, the rule that is being constructed needs to be split. (I think you’d want to take a mapping that is a subset if possible, being greedy when possible.) Given your example:
A => 1,2
B => 1,2,3
C => 3
D => 3,4
Take:
Rule 1: B => 1,2,3
Both A and C have common mappings. Add A, since it has a larger out-degree (we’re being greedy) and split the rule:
Rule 1: A,B => 1,2
Rule 2: B => 3
Now you’re left with C and D. Being greedy, take D. It can be partially added to Rule 2, but must have an additional rule to account for the mapping to 4:
Rule 1: A,B => 1,2
Rule 2: B,D => 3
Rule 3: D => 4
Now you’re left with C, which coincides with Rule 2, so just add it:
Rule 1: A,B => 1,2
Rule 2: B,C,D => 3
Rule 3: D => 4
Naturally, this would be uglier if the mappings of A weren’t a subset of those of B. I seem to have misplaced my algorithms book, otherwise I’d look for an actual known problem. This seems like an (iterated) covering set problem to me, but I may misunderstand what you’re asking.
Y’know, on further reflection, perhaps a better way to visualize this is to try something like a Karnaugh map (as CookingWithGas suggested). Make a matrix of the elements (how does one get fixed width fonts in a post?) like so:
+|1-2-3-4
A|x-x----
B|x-x-x–
C|----x–
D|----x-x
Take out the largest group of x’s that coincide. As in a Karnaugh map, “blocks” of commonality – that is, squares or rectangles of x’s – are best. In this case, it’s A,B and 1,2. (Of course, finding it algorithmically is the problem here. I don’t know how to do it.) The next largest group is B,C,D and 3. Then you’re just left with D, giving:
A,B => 1,2
B,C,D => 3
D => 4
On preview, I note that jawdirk mentioned that he thinks it’s a bipartite graph problem. Either way, it’s nasty. And, if either one of us is correct, it’s NP-hard or NP-complete. But I hope that helped some…