def LCSLength( x, y ):
( m, n ) = length( x, y )
b[ 1 .. m ][ 1 .. n ] = new array
c[ 0 .. m ][ 0 .. n ] = 0
for i = 1 .. m:
for j = 1 .. n:
if x[ i ] == y[ j ]:
c[ i, j ] = c[ i-1, j-1 ] + 1
b[ i, j ] = "UL"
elif c[ i-1, j ] >= c[ i, j-1 ]:
c[ i, j ] = c[ i-1, j ]
b[ i, j ] = "U"
else:
c[ i, j ] = c[ i, j-1 ]
b[ i, j ] = "L"
**Complexity**: *Θ(mn)*
What do "*spanking*" and "*amputation*" have in common?
![LCS example: spanking, amputation](static/img/LCS-spanking-amputation.png)