Shortest common supersequence

From testwiki
Jump to navigation Jump to search

In computer science, the shortest common supersequence of two sequences X and Y is the shortest sequence which has X and Y as subsequences. This is a problem closely related to the longest common subsequence problem. Given two sequences X = < x1,...,xm > and Y = < y1,...,yn >, a sequence U = < u1,...,uk > is a common supersequence of X and Y if items can be removed from U to produce X and Y.

A shortest common supersequence (SCS) is a common supersequence of minimal length. In the SCS problem, two sequences X and Y are given, and the task is to find a shortest possible common supersequence of these sequences. In general, an SCS is not unique.

For two input sequences, an SCS can be formed from a longest common subsequence (LCS) easily. For example, the longest common subsequence of X[1..m]=abcbdab and Y[1..n]=bdcaba is Z[1..L]=bcba. By inserting the non-LCS symbols into Z while preserving their original order, we obtain a shortest common supersequence U[1..S]=abdcabdab. In particular, the equation L+S=m+n holds for any two input sequences.

There is no similar relationship between shortest common supersequences and longest common subsequences of three or more input sequences. (In particular, LCS and SCS are not dual problems.) However, both problems can be solved in O(nk) time using dynamic programming, where k is the number of sequences, and n is their maximum length. For the general case of an arbitrary number of input sequences, the problem is NP-hard.[1]

Shortest common superstring

The closely related problem of finding a minimum-length string which is a superstring of a finite set of strings Template:Var = { Template:Var1,Template:Var2,...,Template:Varn } is also NP-hard.[2] Several constant factor approximations have been proposed throughout the years, and the current best known algorithm has an approximation factor of 2.475.[3] However, perhaps the simplest solution is to reformulate the problem as an instance of weighted set cover in such a way that the weight of the optimal solution to the set cover instance is less than twice the length of the shortest superstring Template:Var. One can then use the [[Approximation algorithm#Performance guarantees|O(log(Template:Var))-approximation]] for weighted set-cover to obtain an O(log(Template:Var))-approximation for the shortest superstring (note that this is not a constant factor approximation).

For any string Template:Var in this alphabet, define Template:Var(Template:Var) to be the set of all strings which are substrings of Template:Var. The instance Template:Var of set cover is formulated as follows:

The instance Template:Var can then be solved using an algorithm for weighted set cover, and the algorithm can output an arbitrary concatenation of the strings Template:Var for which the weighted set cover algorithm outputs Template:Var(Template:Var).Template:Sfn

Example

Consider the set Template:Var = { abc, cde, fab }, which becomes the universe of the weighted set cover instance. In this case, Template:Var = { abcde, fabc }. Then the set of subsets of the universe is

{P(x)|xSM}={P(x)|x{abc,cde,fab,abcde,fabc}}={P(abc),P(cde),P(fab),P(abcde),P(fabc)}}={{a,b,c,ab,bc,abc},{c,d,e,cd,de,cde},,{f,a,b,c,fa,ab,bc,fab,abc,fabc}}}

which have costs 3, 3, 3, 5, and 4, respectively.

References

Template:Reflist