13.07.2015 Views

New Efficient Algorithms for LCS and Constrained LCS Problem

New Efficient Algorithms for LCS and Constrained LCS Problem

New Efficient Algorithms for LCS and Constrained LCS Problem

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!