Algorithm to find edit distance to all substrings

前端 未结 2 2122
不思量自难忘°
不思量自难忘° 2021-02-20 15:05

Given 2 strings s and t. I need to find for each substring in s edit distance(Levenshtein distance) to t. Actually I need to

2条回答
  •  忘了有多久
    2021-02-20 15:28

    The Wagner-Fischer algorithm gives you the answer for all prefixes "for free".

    http://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm

    The last row of the Wagner-Fischer matrix contains the edit distance from each prefix of s to t.

    So as a first crack at your problem, for each i, run Wagner-Fischer and select the smallest element in the last row.

    I will be curious to see if anyone else knows (or can find) a better approach.

提交回复
热议问题