18k-1090 18k0429 An Efficient Algorithm For LCS Problem Between Two Arbitrary Sequences
18k-1090 18k0429 An Efficient Algorithm For LCS Problem Between Two Arbitrary Sequences
18k0429
This research article explores the classic problem of Longest Common Subsequence (LCS) by
briefly describing the time and space complexities of existing algorithms in this area, and also
proposes a new algorithm with the space complexity of O(n+r) and time complexity of O(r + n^2)
time — where r is the total number of elements in the set {(i, j) | such that s1[i] = s2[j]} — for certain
ranges of r.
While generally, with the random or arbitrary number of input sequences the LCS algorithms can
be NP-hard, with the number of sequences fixed, the degree of complexity is polynomial at the
minimum. Assuming the limitation of two input sequences, this paper presents a more efficient
algorithm.
LCS is the biggest or longest subsequence that is the same for all the sequences in a collection. This
subsequence does not necessarily have to be unique or possess consecutive/contiguous places in the
original sequences (for eg. , fafa is the longest common subsequence between nfafa and fanfa). The
longest rising subsequence. “Longest Increasing Subsequence(LIS) is a subsequence of a given
sequence in which the subsequence's elements are in sorted order” (ascending order) , where the
particular subsequence is as long as possible.
This particular subsequence is never striclty consecutive or follows one after another. The longest
rising subsequence of {1, 4, 2, 3}, therefore is (1, 2, 3). LIS(seq) is a given function that returns a
set that contains all of a sequence's LISs.
If s1 = xnfafa and s2 = yfanfa, Assume there is a sequence l, whose elements are vectors in the form
of I j) for all s1[i] = s2[j] . The left half of an element of l(l[u][0]) represents the symbol's position
in s1, and the right part of the element (l[u][1]) represents the symbol's position in s2. L is ordered
in ascending order using l[u][0] as the first key and descending order using l[u][1]. Define (Iu, Ju),
(Iv, Jv) ∈ l, (Iu < Iv) ∧ (Ju Jv) <-- (Iu, Ju) < (Iu, Ju). It is a bijective mapping between LIS(l) and
LCS(s1, s2) while LIS(l) is associated with LCS(s1, s2) (s1, s2). As a result, LCS(s1, s2) is reduced
to LIS(l)[25]. The proposed algorithm reduces the LCS2 problem to a LIS problem.
Illustration Figure 1:
The Algorithm :
For the problem,
s1 = xnfafa, s2 = yfanfa, the following steps should be taken in keeping with the algorith presented
above:
Algorithm Walkthrough:
→ As the length of LCS is in the degree of order of n ( O(n) ), step 3 has the
space complexity of O(r) and time complexity of O(n).
→ Step 4 consequently has time and space complexity of O(n)