Jump to content

Shortest common supersequence

From Wikipedia, the free encyclopedia

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

[edit]

The closely related problem of finding a minimum-length string which is a superstring of a finite set of strings S = { s1,s2,...,sn } is also NP-hard.[2] Moreover, it is APX-complete.[3] Several constant-factor approximation algorithms have been proposed. As of 2023, the best published approximation ratio was (67+14)/9≈2.466,[4] a slight improvement on a ratio of about 2.475 from 2022.[5] 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 S. One can then use the O(log(n))-approximation for weighted set-cover to obtain an O(log(n))-approximation for the shortest superstring (note that this is not a constant factor approximation).

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

  • Let M be empty.
  • For each pair of strings si and sj, if the last k symbols of si are the same as the first k symbols of sj, then add a string to M that consists of the concatenation with maximal overlap of si with sj.
  • Define the universe 𝒰 of the set cover instance to be S
  • Define the set of subsets of the universe to be { P(x) | x ∈ S ∪ M }
  • Define the cost of each subset P(x) to be |x|, the length of x.

The instance I can then be solved using an algorithm for weighted set cover, and the algorithm can output an arbitrary concatenation of the strings x for which the weighted set cover algorithm outputs P(x).[6]

Example

[edit]

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

{P(x)|x∈S∪M}={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.

Greedy algorithm

[edit]

A simple greedy algorithm repeatedly merges the two strings with the largest overlap until a single string remains. Tarhio and Ukkonen conjectured in 1988 that this algorithm always produces a superstring at most twice as long as the shortest one, a statement known as the greedy conjecture.[7][4] Blum et al. proved an upper bound of 4 on its approximation ratio, and later work reduced this to about 3.396.[4]

See also

[edit]

References

[edit]
  1. ↑ David Maier (1978). "The Complexity of Some Problems on Subsequences and Supersequences". J. ACM. 25 (2). ACM Press: 322–336. doi:10.1145/322063.322075. S2CID 16120634.
  2. ↑ Kari-Jouko Räihä, Esko Ukkonen (1981). "The shortest common supersequence problem over binary alphabet is NP-complete". Theoretical Computer Science. 16 (2): 187–198. doi:10.1016/0304-3975(81)90075-x.
  3. ↑ Blum, Avrim, Tao Jiang, Ming Li, John Tromp, and Mihalis Yannakakis. "Linear approximation of shortest superstrings." Journal of the ACM (JACM) 41, no. 4 (1994): 630-647.
  4. 1 2 3 Englert, Matthias; Matsakis, Nicolaos; Veselý, Pavel (2023). "Approximation guarantees for shortest superstrings: simpler and better". 34th International Symposium on Algorithms and Computation (ISAAC 2023). Leibniz International Proceedings in Informatics (LIPIcs). Vol. 283. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. pp. 29:1–29:17. doi:10.4230/LIPIcs.ISAAC.2023.29.
  5. ↑ Matthias Englert and Nicolaos Matsakis and Pavel Veselý (2022). "Improved approximation guarantees for shortest superstrings using cycle classification by overlap to length ratios". Proceedings of the 54th Annual ACM SIGACT Symposium on Theory of Computing (PDF). pp. 317–330. doi:10.1145/3519935.3520001. ISBN 9781450392648. S2CID 243847650.
  6. ↑ Vazirani 2001, p. 20.
  7. ↑ Tarhio, Jorma; Ukkonen, Esko (1988). "A greedy approximation algorithm for constructing shortest common superstrings". Theoretical Computer Science. 57 (1): 131–145. doi:10.1016/0304-3975(88)90167-3.
[edit]