






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
please download for Longest Common Subsequent DAA
Typology: Study notes
1 / 11
This page cannot be seen from the preview
Don't miss anything!
S1 : A -- A T -- G G C C -- A T A n= S2: A T A T A A T T C T A T -- m=
The LCS is AATCAT. The length of the LCS is 6. The solution is not unique for all pair of strings. Consider the pair ( ATTA, ATAT ). The solutions are ATT, ATA. In general, for arbitrary pair of strings, there may exist many solutions.
The LCS can be found by dynamic programming formulation. One can easily show: Theorem: With a score of 1 for each match and a zero for each mismatch or space , the matched characters in an alignment of maximum value for a LCS. Since it is using the general dynamic programming algorithm its complexity is O(nm). A longest substring problem, on the other hand has a O(n+m) solution. Subsequences are much more complex than substrings. Can we do better for the LCS problem? We will see …
The optimal alignment is shown above. Note the alignment shows three insert (dark), one delete green) and three substitution or replacement operations (blue), which gives an edit distance of 7. But, the 3 replacement operations can be realized by 3 insert and 3 delete operations because a replacement is equivalent to first delete the character and then insert a character in its place like:
S1 : A -- A T -- G G C C -- A T A n= S2: A T A T A A T T C T A T -- m=
G -- G -- C -- -- A -- T -- T
D = m + n − 2 L
An algorithm that is asymptotically better than O ( nm ) for determining LCS. Implies that for special cases of edit distance, there exist more efficient algorithm. Definition: Let π be a set of n integers, not necessarily distinct. Definition: An increasing subsequence(IS) of π is a subsequence of π whose values are strictly increasing from left to right. Example: π=(5,3,4,4, 9,6,2,1,8,7,10). IS= (3,4,6,8,10), (5,9,10)
A longest increasing subsequence(LIS) of π is an IS π of maximum length.
A decreasing subsequence (DS) of π is a non- increasing subsequence f π.
A cover is a set of disjoint DS of π that covers or contains all elements of π. The size of the cover c equals the number of DS in the cover.
A smallest cover ( SC ) is a cover with a minimum value of c.
Determine LIS and SC simultaneously in
O(nlogn)
If I is an IS of π with length equal to the size of a cover C of π, then I is a LIS of π and C is the smallest cover of size c.
We use a data structure which is a list containing the last number of each of the decreasing sequence that is being constructed.
The list is always sorted in increasing order. An identifier indicating which list the number belongs to also included.
Procedure Decreasing Sequence Cover
Input: π= , the list of input numbers.
Output: the set of decreasing sequences Di constituting the cover.
( x 1 , x 2 ,......... xn )
Initialize: i ←1; Di =( x1 ); L= ( x1 , i ) ; j ←1; For i =2 to n do Search the x -fields of L to find the first x- value such that xi < x. ….takes O ( logn ) time. If such a value exists, then insert x at the end in the list Di and set xi ← x in L… This step takes constant time. If such a value does not exist in L , then set j ← j+ 1. insert in L a new element ( x,j ) and start a new decreasing sequence Dj =( x ) End
Lemma: At any point in the execution of the algorithm the list L is sorted in increasing order with respect to x -values as well as with respect to identifier value.
In fact two separate lists will be better from practical implementation point of view.
Theorem: The greedy cover can be constructed taking O ( nlogn ) time. A longest increasing sequence and a smallest cover thus can be constructed using O ( nlogn ) time.
for each distinct character x in S1, define list(x) to be the positions of x in S2 in decreasing order.
Theorem: Every increasing sequence I of Π ( S1,S2 ) specifies an equal length common subsequence of S 1 and S 2 and vice versa. Thus a longest common subsequence LCS of S 1 and S 2 corresponds to a longest increasing sequence of Π ( S1,S2 ).
Example: Π ( S1,S2 )= (6,3,2,4,1,6,3,2,5). The possible longest increasing sequences used as indices to access the characters in S2 yield the LCS as: (1,2,5)= b a c , (2,3,5)= a a c , (3,4,6)= a b a for S1 = a b a c x an d S2 = b a a b c a.