Question

A string x is called a supersequence of a string v if v is a subsequence...

A string x is called a supersequence of a string v if v is a subsequence of x. For example, ABLUE is a supersequence for BLUE and ABLE. Given strings v and w, devise an algorithm to find the shortest supersequence for both v and w.

Homework Answers

Answer #1

The algorithm is given as:

ALGORITHM

Let U[0..m - 1] and V[0..n - 1] be two strings and m and n the length of U and V, respectively.

function ShortestCommonSupersequence(U, V, m, n) {

if (m == 0) return n

if (n == 0) return m

// If last characters are same, then add 1 to result and recur for U[]

if (U[m - 1] == V[n - 1])

return 1 + ShortestCommonSupersequence(U, V, m - 1, n - 1)

// Else find shortest of following two

// a) Remove last character from U and recur

// b) Remove last character from V and recur

else return 1 + min( ShortestCommonSupersequence(U, V, m - 1, n), ShortestCommonSupersequence(U, V, m, n - 1) );

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java Lab Assignment Write a method called convertToArray. The method will take a String as an...
Java Lab Assignment Write a method called convertToArray. The method will take a String as an argument and it will return an array of chars. Each index of the String will be stored in each index of the array. method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for * @return...
LCS (Longest Common Subsequence) problem consists in finding the longest subsequence of characters that is present...
LCS (Longest Common Subsequence) problem consists in finding the longest subsequence of characters that is present in two given sequences in the same order. A subsequence is a sequence of characters that don't have to be consecutive. For example, for the following inputs, the length of the LCS is 4 X: ABCBDAB Y: BDCABA And one of the LCS is BDAB The following code is a solution for such problem, which values must be stored in the variable key for...
String array operations a. Create a string array called myInformationcontaining the following entries in order: Your...
String array operations a. Create a string array called myInformationcontaining the following entries in order: Your full name The name of the town or city where you were born Your major The name of this university with only the first letter of each word capitalized; don’t forget the “The”! b. Use the Matlab function strcmp to compare the name of the university as you defined it against the following two strings: i. “The Ohio State University” ii. “THE OHIO STATE...
Find numbers x and y so that w-x⋅u-y⋅v is perpendicular to both u and v, where...
Find numbers x and y so that w-x⋅u-y⋅v is perpendicular to both u and v, where w=[-28,-25,39], u=[1,-4,2], and v=[7,3,2].
It is not true that the equality u x (v x w) = (u x v)...
It is not true that the equality u x (v x w) = (u x v) x w for all vectors. 1. Find explicit vector for u, v and w where this equality does not hold. 2. U, V and W are all nonzero vectors that satisfy the equality. Show that at least one of the conditions below holds: a) v is orthogonal to u and w. b) w is a scalar multiple of u. You can possibly use a...
Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit...
Demonstrate your continuous progress in learning MIPS assembly by writing and executing the program below. Edit the program using your favorite code editor (e.g. Notepad++) and load the programs into QtSpim for execution. Activity Directions: Write a program that will read a line of text and determine whether or not the text is a palindrome. A palindrome is a word or sentence that spells exactly the same thing both forward and backward. For example, the string “anna” is a palindrome,...
Java Lab Assignment Write a method called convertToString. The method will take an array of chars...
Java Lab Assignment Write a method called convertToString. The method will take an array of chars as an argument and it will return a String. Each index of the array will be part of the each index of the String. method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for *...
Perform resolution. What can you conclude about this set of clauses? 1. W v ~X v...
Perform resolution. What can you conclude about this set of clauses? 1. W v ~X v ~Y v Z 2. ~W v ~X v ~Y v Z 3. X v Y v Z 4. W v ~Z 5. ~W '~' denotes negation and 'v' denotes union Given these clauses in CNF, perform resolution
Consider a infinite string made by joining a semi-infinite string of density ρ1 (x < 0)...
Consider a infinite string made by joining a semi-infinite string of density ρ1 (x < 0) to another semi-infinite string of density 4ρ1 (x > 0) with the combination held under constant tension, T. A transverse sinusoidal wave of amplitude A(inc) and wavelength λ propagates to the right along the string of lower density towards the interface. (i) Find the amplitude and wavelength of the wave when it is travelling along the heavier string. What fraction of the time-averaged energy...
Write a Turing-machine style of algorithm to decide the language L2 given below. Use specific, precise,...
Write a Turing-machine style of algorithm to decide the language L2 given below. Use specific, precise, step-by-step English. So, describe how to test whether or not an input string is in the language L2 in finite time. No need to write a state diagram. L2 = {w : w has more a’s than it has b’s and c’s combined} over the alphabet Σ = {a, b, c}. Example strings: abaca ∈ L2. bcaa ∉ L2.