SourceForge.net Logo

Longest Common Subsequence Simulation (LCS)

Input X
Input Y
Max Size: 7
Sequences:
Char Variant: 4
 
i:0
j:0
Xi:0
Yj:0
Step:
LCS-LENGTH(X, Y)
1m = length[X]
2n = length[Y]
3for i = 1 to m
4do c[i, 0] = 0
5for j = 1 to n
6do c[0, j] = 0
7for i = 1 to m
8do for j = 1 to n
9do if Xi == Yj
10then c[i, j] = c[i-1, j-1] + 1
11b[i, j] = ARROW_CORNER
12else if c[i-1, j] >= c[i, j-1]
13then c[i, j]=c[i-1, j]
14b[i, j] = ARROW_UP
15else c[i, j]=c[i, j-1]
16b[i, j] = ARROW_LEFT
17return c and b
PRINT-LCS(b, X, i, j)
1
2
3
4
5
6
7
8