Question

Longest common subsequence (LCS) algorithms give a way to decide how similar two given strings are....

Longest common subsequence (LCS) algorithms give a way to decide how similar two given strings are. However, sometimes, we have to filter away some common subsequences that are in some pattern. Here is a problem for you to solve. Given two strings alpha and beta, let gamma to be the longest word satisfying all of the following conditions: gamma is a subsequence of alpha. gamma is a subsequence of beta. gamma does not contain abb. Design an algorithm that finds such a gamma for any given alpha and beta. Also, analyze its time complexity.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function LCSLength(X[1..m], Y[1..n])
C = array(0..m, 0..n)
for i := 0..m
C[i,0] = 0
for j := 0..n
C[0,j] = 0
for i := 1..m
for j := 1..n
if X[i] = Y[j]
C[i,j] := C[i-1,j-1] + 1
else
C[i,j] := max(C[i,j-1], C[i-1,j])
return C[m,n

Screenshot:

after getting the LCS, search for string 'abb'

if 'abb' is substring of obtained LCS

earse 'abb' from LCS.

Note: Please consider my work and give up vote. Thank you :)

Add a comment
Know the answer?
Add Answer to:
Longest common subsequence (LCS) algorithms give a way to decide how similar two given strings are....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. (40 pts) Let A, B, and C be three strings each n characters long. We want to compute the longest subsequence that is...

    2. (40 pts) Let A, B, and C be three strings each n characters long. We want to compute the longest subsequence that is common to all three strings. (a) Let us first consider the following greedy algorithm for this problem. Find the longest common subsequence between any pair of strings, namely, LCS(A, B) LCS(B, C), LCS(A, C). Then, find the longest common subsequence between this LCS and the 3rd string. That is, supposing that the longest common pair wise...

  • 2. (40 pts) Let A, B, and C be three strings each n characters long. We want to compute the longest subsequence th...

    2. (40 pts) Let A, B, and C be three strings each n characters long. We want to compute the longest subsequence that is common to all three strings. (a) Let us first consider the following greedy algorithm for this problem. Find the longest common subsequence between any pair of strings, namely, LCS(A, B). LCS(B,C), LCS(A, C). Then, find the longest common subsequence between this LCS and the 3rd string. That is, supposing that the longest common pair wise subsequence...

  • Give an O(n2 ) algorithm (Pseudocode) that, given a sequence S, finds the longest subsequence that...

    Give an O(n2 ) algorithm (Pseudocode) that, given a sequence S, finds the longest subsequence that first increases then decreases. For instance, in the sequence S = [10, 4, 5, 11, 2, 7, 4, 3, 9] the longest such subsequence is [4,5,11,7,4,3]. The subsequence does not have to be consecutive. (Hint: Use two arrays, one for increasing subsequences and the other for decreasing subsequences.)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT