zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    Java 初始化
    tomcat 输入学习
    使用exundelete在Linux下恢复删除的文件
    java设计模式----解释器模式
    java设计模式----中介模式
    java设计模式----访问者模式
    java设计模式----状态模式
    关于前后端分离的一些事
    sublime text3
    java中的socket编程
  • 原文地址:https://www.cnblogs.com/yayagamer/p/2262862.html
Copyright © 2011-2022 走看看