LCS_length (X,Y)
N = length (X)
P = length (Y)
b = 2D array of N+1 rows, P+1 columns
c = 2D array of N+1 rows, P+1 columns
for i = 0 to N
c[i,0] = 0
for j = 0 to P
c[0,j] = 0
for i = 1 to N
for j = 1 to P
if $X_{i-1} == Y_{j-1}$
c[i,j] = c[i-1,j-1]+1
b[i,j] = \\ // diagonal
else if c[i-1,j]?c[i,j-1]
c[i,j] = c[i-1,j]
b[i,j] = ^ // up arrow
else
c[i,j] = c[i,j-1]
b[i,j] = < // left arrow