Minimum edit distance problem

You are given a word and a dictionary. Now propose an algorithm edit the word (insert / delete characters) minimally to get a word that also exists in the dictionary. Cost of insertion and deletion is same. 
Write pseudocode for it.

Seems like minimum edit distance problem but some modification is
needed.

 

Updated:

A1: 设m 为word的平均长度

1) 对于输入的word的每一位,改变其字符,有25种可能(假设只可能是26个英文字母),所以每一位改变一次,时间为O(m),然后去dictionary中去查找,是否存在(假设查询是O(1),即hash的速度),则总体时间复杂度为O(m)。如果找到了,则结束,如果没有找到,则the following

2) 再一次改变word的两个字母,时间复杂度O(m^2)

3) 所以,总时间复杂度为O(m^3)

 

A2:用edit distance algo

1) 遍历dictionary,计算edit distance between word and dictionary[i], distance最小的都是符合要求的。O(m^2)

2) 取出距离最小的words和原来的word比较,找到需要改变的字符位置。O(m^2)

总的时间复杂度, O(m^2)

 

posted @ 2011-11-25 11:07  百分百好牛  阅读(240)  评论(0编辑  收藏  举报