22 November 2012

LCS ALGORITHM

 Longest Common Sub-sequence Algorithm

                                                                

lcs(x,y)
m = x.length
n  = y.length

let   b[1-m , 1-n]   &  c[0-m , 0-n] be a new table 

for i=1 to m
c[i,0]=0

for j=0 to n
c[o,j]=0

for i=1 to m   
   for j=1 to n
          if(xi==yj)
             c[i,j]=c[i-1,j-1]+1
             b[i,j]=" \ "
          else
             if(c[i-1,j]>=c[i,j-1])
                  c[i,j]=c[i-1,j]
                  b[i,j]=" I "
              else
                  c[i,j]=c[i,j-1]
                  b[i,j]=" <-"

        return c & b 
                                                  By - Seevendra Dwivedi