Convert one string S1 to another string S2 using only 3 types of operations

Q: Suppose we want to convert one string S1 to another string S2 using only 3 types of operations: 

-Insert(pos,char) (costs 8) 
-Delete(pos) (costs 6) 
-Replace(pos,char) (costs 8) 
Find the sequence of steps to convert S1 to S2 such that the cost to convert S1 to S2 is minimum. 
Eg. 'calculate' to 'late' - the possible operations are 
Delete(0) 
Delete(1) 
Delete(2) 
Delete(3) 
Delete(4) 
and the above sequence of operations costs 30.

 

A: some ideas

1) using levenshtein algorithm

2) Is this the minimum edit distance algorithm. You can look it up at various sources, some of them listed below (AKA "Levenshtein distance"): 

w_ww.stanford.edu/class/cs124/lec/med.pdf 
w_ww.csse.monash.edu.au/~lloyd/tildeAlgDS/Dynamic/Edit/ 
e_n.wikipedia.org/wiki/Levenshtein_distance

 

3) find longest common subseuqence, and use the avail operations on the rest of the characters.

posted @ 2013-04-24 17:18  百分百好牛  阅读(221)  评论(0编辑  收藏  举报