Hi again,
thanks @PrivateRyan for suggestions.
I think my problem is strictly related to the "
Shortest common supersequence problem" (
https://en.wikipedia.org/wiki/Shortest_common_supersequence_problem)
Answering to @Arslan7041 I can provide a new example:
Please consider,
this set of size five { 01 02 03 04 05 },
it generates the subsets of size four
{ 01 02 03 04 }
{ 01 02 03 05 }
{ 01 02 04 05 }
{ 01 03 04 05 }
{ 02 03 04 05 }
while this other set of five { 01 02 10 13 39 }
it generates
{ 01 02 10 13 }
{ 01 02 10 39 }
{ 01 02 13 39 }
{ 01 10 13 39 }
{ 02 10 13 39 }
(you can easily generate subsets of size four just removing one item each time starting from the five item set)
So, if I am processing the following input
(that is a ordered list of sets of size four, and don’t know which sets of size five I can make yet)
01 02 03 04
01 02 03 05
01 02 04 05
01 02 10 11
01 02 10 12
01 02 10 13
01 02 10 14
01 02 10 35
01 02 10 39
01 02 12 21
01 02 12 30
01 02 12 36
01 02 13 39
01 03 04 05
01 10 13 39
02 10 13 39
02 03 04 05
09 10 11 12
The ouptut should be:
01 02 03 04 05
01 02 10 13 39
Infact, as you can see I found in the input:
-all subsets (a) I need for building the set A= 01 02 03 04 05 (first line of the output)
and also
-all subsets (b) I need for building the set B= 01 02 10 13 29 (second line)
01 02 03 04 (a)
01 02 03 05 (a)
01 02 04 05 (a)
01 02 10 11
01 02 10 12
01 02 10 13 (b)
01 02 10 14
01 02 10 35
01 02 10 39 (b)
01 02 12 21
01 02 12 30
01 02 12 36
01 02 13 39 (b)
01 03 04 05 (a)
01 10 13 39 (b)
02 10 13 39 (b)
02 03 04 05 (a)
09 10 11 12
I think I will try with this approach:
1) I'll examine a line of the input (i.e 01 02 03 04)
2) I'll search until I find a set that have 3 common items (01 02 03 05)
3) If I found second sets with 3 common items with the first one I'll build the 5 items set and I'll generate all subsets of size four (i.e all the (a) sets).
3.1) Then I'll scan again to see if I have all the generated subsets in my input.
- If I have all the generated subset in my input I'll delete (or check as used), then I'll go to the step 1)
- If I don't have all the generated subset in my input I'll repeat the step 2) to search for the next set with 3 common items..(while not end of file)
4) I'll examine the next (unsigned) line of the input and go to step 2)
this until the end of file
Thanks again for your replays.