Search code examples
algorithmgraph-theoryset-theory

How to find the shortest path that pass through a group of Sets?


I have an algorithmic problem where I have a number of Unordered Sets of elements, and I need to find the shortest path (Ordered combination of the sets) that pass through all of those sets. There may be thousands of sets.

For example, let there be the following 4 unordered sets:
A=abcdefg
B=cd
C=abch
D=defi

The shortest path size is 11.

One possible solution is:
P=CADB=habcgdeficd
|P|=11

Note that sets may share elements with neighboring sets in the path!
There may also be duplicated elements belonging to different sets (as in the example above: 'c' and 'd' are duplicated in P, by adding B to CAD).

Please advise with an algorithm to find the shortest path as described.
Thanks!


Solution

  • This question can be reduced to a variation of the Shortest common superstring problem