开发者

Minimum Number of Operations needed

I have a problem, suppose I have a given string: "best", the target string is suppose: "beast". Then I have to determine the number of operations to convert the given string to the target string, however the operations allowed are: 1. add a character to string. 2. delete a character. 3. swap two char positions. (should be used wisely, we have o开发者_如何学编程nly one chance to swap.)

In above case it is 1. How do we solve such kind of problem, and what kind of problem is it? I am a newbie learner.


One widely-used measure of this kind of thing is called the Levenshtein distance.

http://en.wikipedia.org/wiki/Levenshtein_distance

The WP page also mentions/links to other similar concepts. It is essentially a metric of the number of edits needed to turn one word into another.


Levenshtein distance

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜