Similarity(X,Y):
For i = 0,...,m: SIM[i,0] = ig
For j = 1,...,n: SIM[0,j] = j
g
For i = 1,...,m:
For j = 1,...,n:
SIM[i,j] = max(
SIM[i-1,j-1] + s(X[i],Y[j]),
SIM[i-1,j]+g,
SIM[i,j-1]+g
)
EndFor
EndFor
Return SIM[m,n]

Well, it could be something like

def Similarity(X,Y):
    for i in range(m+1):
        SIM[i,0] = ig
    for j in range(1, n+1):
        SIM[0,j] = jg
    for i in range(1, m+1):
        for j in range(1, n+1):
            SIM[i,j] = max(
                SIM[i-1,j-1] + s(X[i],Y[j]),
                SIM[i-1,j]+g,
                SIM[i,j-1]+g
            )
    return SIM[m,n]

but we don't know what X, Y, SIM, ig, jg , g are, so it does not mean much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.