Practice Sheet 4 2016 Practice Sheet 4 2016
Practice Sheet 4 2016 Practice Sheet 4 2016
4. (Edit Distance)
Given two text strings A of length n and B of length m, you want to transform A into
B with a minimum number of operations of the following types: delete a character
from A, insert a character into A, or change some character in A into a new character.
The minimal number of such operations required to transform A into B is called the
edit distance between A and B. Design a polynomial time algorithm to compute edit
distance between A and B.
1
Downloaded by Subham Kumar ([email protected])
lOMoARcPSD|9106035
• (((M1 × M2 ) × M3 ) × M4 )
• ((M1 × M2 ) × (M3 × M4 ))
• (M1 × ((M2 × M3 ) × M4 ))
• (M1 × (M2 × (M3 × M4 )))
The number of ways to parenthesize the expression is exponential (it is catalan num-
ber). Of course, we can not afford to try out each possible way to multiply the n
matrices.
Hint: Consider that parenthesized expression that corresponds to the least number
of multiplication operations. If you multiply the matrices according to this parenthe-
sization, the number of matrices will reduce by 1 each time. Finally we will be left
with only 2 matrices. How do these last two matrices which are multiplied look like
? What can you infer from it ? Use it to come up with a recursive formulation.
2
Downloaded by Subham Kumar ([email protected])