Let X and Y be the two strings we want to find the length of the LCS of, and Xiβ = <X0β , X1β,..., Xiβ> and Yjβ = <Y0β, Y1β,..., Yjβ>.
Xiβ and Yjβ are called prefixes of the strings X and Y.
Further, let c[i,j] be the length of the optimal LCS of the prefixes Xiβ and Yjβ. Then we can have the relation:
c[i,j]=β©β¨β§β0c[iβ1][jβ1]+1max(c[i,jβ1],c[iβ1,j])βΒ ifΒ i=0Β orΒ j=0Β ifΒ i,j>0Β andΒ xiβ=yiβΒ ifΒ i,j>0Β andΒ xiβξ =yjββ