Algorithm 2 AlgC<strong>LCS</strong><strong>New</strong>1: Construct the set M using Algorithm 1 of [24]. Let M i = (i, j) ∈ M, 1 ≤ j ≤ n.2: globalC<strong>LCS</strong>.Instance = ɛ3: globalC<strong>LCS</strong>.Value = ɛ4: H −10 = ɛ5: H 0 0 = ɛ6: <strong>for</strong> i = 1 to n do7: <strong>for</strong> k = 0 to p do8:9:Hi k = Hi−1k<strong>for</strong> each (i, j) ∈ M i do10: max 1 = BoundedMax(H k−1i−1 , j)11: max 2 = BoundedMax(Hi−1, k j){First, we consider Equations 7 <strong>and</strong> 8}12: Val 2 .Value = 013: Val 2 .Instance = ɛ14: if ((k = 0) or (max 2 .Value > 0)) then15: Val 2 = max 216: end if{Now, we consider Equations 5 <strong>and</strong> 6}17: if (X[i] = Z[k]){This means X[i] = Y [j] = Z[k]} then18: Val 1 .Value = 019: Val 1 .Instance = ɛ20: if (k = 1) or ((k > 1) <strong>and</strong> (max 1 .V alue > 0)) then21: Val 1 = max 122: end if23: end if{Finally, we consider Equation 2}24: maxresult = max{Val 1 , Val 2 }25: T k [i, j].Value = maxresult.Value + 126: T k [i, j].Prev = maxresult.Instance27: if global<strong>LCS</strong>.Value < T k [i, j].Value then28: global<strong>LCS</strong>.Value = T k [i, j].Value29: global<strong>LCS</strong>.Instance = (i, j, k)30: end if31: IncreaseValue(Hi k , j, T [i, j].Value, (i, j, k)).32: end <strong>for</strong>33: Delete H k−1i−1 .34: end <strong>for</strong>35: end <strong>for</strong>36: return global<strong>LCS</strong>
– We update H k i , which is initialized to H k i−1 when we start row i. H k i is later usedwhen we consider the matches of row i + 1 of the two matrices T k <strong>and</strong> T k+1Due to Fact 4, while computing a T k [i][j], (i, j) ∈ M, 1 ≤ i, j ≤ n, 1 ≤ k ≤ p, we canemploy the same technique with Hi k , Hi−1 k <strong>and</strong> H k−1i−1 used in Alg<strong>LCS</strong><strong>New</strong> (with H i<strong>and</strong> H i−1 to compute T [i, j], (i, j) ∈ M, 1 ≤ j ≤ n). On the other h<strong>and</strong>, courtesyto Fact 3, to realize Equations 5−8, we need only keep track of H k−1i−1 <strong>and</strong> Hk i−1. Thesteps are <strong>for</strong>mally stated in Algorithm 2. In light of the analysis of Alg<strong>LCS</strong><strong>New</strong>, it isquite easy to see that the running time is O(pR log log n + n). The space complexity,like Alg<strong>LCS</strong><strong>New</strong>, is dominated by the preprocessing step of [24] because in the mainalgorithm, we only need to keep track of 3 BoundedHeap data structures <strong>and</strong> thethird string Z, requiring in total O(n) space.Theorem 3. <strong>Problem</strong> C<strong>LCS</strong> can be solved in O(pR log log n + n) time requiringθ(max{R, n}) space.5 ConclusionIn this paper, we have studied the classic <strong>and</strong> well-studied longest common subsequence(<strong>LCS</strong>) problem <strong>and</strong> a recent variant of it namely constrained <strong>LCS</strong> (C<strong>LCS</strong>)problem. In <strong>LCS</strong>, given two strings, we want to find the common subsequence havingthe highest length; in C<strong>LCS</strong>, in addition to that, the solution to the problemmust also be a supersequence of a third given string. The traditional <strong>LCS</strong> problemhas extensive applications in diverse areas of computer science including DNA sequenceanalysis, genetics <strong>and</strong> molecular biology. C<strong>LCS</strong>, a relatively new variant of<strong>LCS</strong>, gets its motivation from computational bio-in<strong>for</strong>matics as well. In this paper,we have presented an efficient algorithm <strong>for</strong> the traditional <strong>LCS</strong> problem that runsin O(R log log n + n) time. Then, using this algorithm, we have devised an algorithm<strong>for</strong> the C<strong>LCS</strong> problem having time complexity O(pR log log n + n) in the worst case.Note that, if R = o(n 2 ), our algorithm will per<strong>for</strong>m very well but, if R = O(n 2 ), then,due to the log log n term, our algorithms will behave slightly worse than the existingalgorithms. It would be interesting to see whether our techniques can be employed toother variants of <strong>LCS</strong> problem to devise similar efficient algorithms.References1. V. Arlazarov, E. Dinic, M. Kronrod, <strong>and</strong> I. Faradzev. On economic construction of the transitive closureof a directed graph (english translation). Soviet Math. Dokl., 11:1209–1210, 1975.2. A. N. Arslan <strong>and</strong> Ö. Eğecioğlu. <strong>Algorithms</strong> <strong>for</strong> the constrained longest common subsequence problems.In M. Simánek <strong>and</strong> J. Holub, editors, The Prague Stringology Conference, pages 24–32. Department ofComputer Science <strong>and</strong> Engineering, Faculty of Electrical Engineering, Czech Technical University, 2004.3. A. N. Arslan <strong>and</strong> Ö. Eğecioğlu. <strong>Algorithms</strong> <strong>for</strong> the constrained longest common subsequence problems.Int. J. Found. Comput. Sci., 16(6):1099–1109, 2005.4. S. Bereg <strong>and</strong> B. Zhu. RNA multiple structural alignment with longest common subsequences. InL. Wang, editor, Computing <strong>and</strong> Combinatorics (COCOON), volume 3595 of Lecture Notes in ComputerScience, pages 32–41. Springer, 2005.