ArticleslgStudy

computer science

Shortest common supersequence

Shortest common supersequence is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Shortest common supersequence rather than just read about it. In short: 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.

Key takeaways

  • Shortest common supersequence belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Shortest common supersequence to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Shortest common supersequence from memory before moving on to harder problems.

Reference excerpt

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.

Shortest common superstring 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. Moreover, it is APX-complete. Several constant-factor approximation algorithms have been proposed. As of 2023, the best published approximation ratio was (67+14)/9≈2.466, a slight improvement on a ratio of about 2.475 from 2022. 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).

Example 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 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. Blum et al. proved an upper bound of 4 on its approximation ratio, and later work reduced this to about 3.396.

See also Longest common subsequence Longest common substring Superpermutation, a special case of the common superstring problem for S the set of n! permutations of a set of n distinct letters.

References

Garey, Michael R.; Johnson, David S. (1979). Computers and Intractability: A Guide to the Theory of NP-Completeness. W.H. Freeman. p. 228 A4.2: SR8. ISBN 0-7167-1045-5. Zbl 0411.68039. Szpankowski, Wojciech (2001). Average case analysis of algorithms on sequences. Wiley-Interscience Series in Discrete Mathematics and Optimization. With a foreword by Philippe Flajolet. Chichester: Wiley. ISBN 0-471-24063-X. Zbl 0968.68205. Vazirani, Vijay V. (2001), Approximation Algorithms (PDF), Springer-Verlag, ISBN 3-540-65367-8

External links Dictionary of Algorithms and Data Structures: shortest common supersequence Shortest Common Supersequence 1092. Shortest Common Supersequence Shortest Common Supersequence Shortest common supersequence Shortest Common Supersequence (SCS)

Worked examples

Example 1 — a first encounter with Shortest common supersequence

Start with the simplest possible case. Write down what Shortest common supersequence claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Shortest common supersequence before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Shortest common supersequence ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Shortest common supersequence

In research
Shortest common supersequence appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Shortest common supersequence in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Shortest common supersequence is common in secondary-school and first-year university syllabi. It links to neighbouring topics Approximation algorithms, Combinatorics, Dynamic programming, so understanding it makes those chapters shorter.
In everyday life
Look for Shortest common supersequence outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Shortest common supersequence” →

How to study Shortest common supersequence in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Shortest common supersequence means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Shortest common supersequence out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Shortest common supersequence in simple terms?

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.

Why does Shortest common supersequence matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Shortest common supersequence?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Shortest common supersequence.

Tags

  • Approximation algorithms
  • Combinatorics
  • Dynamic programming
  • Formal languages
  • NP-complete problems
  • Problems on strings

Keep exploring