1

I'm not sure I've titled this post correctly, but I'm wondering if there's a name for this type of algorithm:

What I'm trying to accomplish is to create a minimal set of instructions to go from one string to its permutation, so for example:

    STACKOVERFLOW -> STAKCOVERFLOW

would require a minimum of one operation, which is to

    shift K before C.

Are there any good online examples of

  1. Finding the minimum instruction set (I believe this is also often called the edit distance), and
  2. Listing the instruction set

Thanks!

4
  • what language? Please provide a complete description of your problem, if you want to get a helpful answer Commented Aug 19, 2011 at 22:48
  • Take a look at this link: norvig.com/spell-correct.html It's pretty good. Commented Aug 19, 2011 at 22:52
  • I'm happy with any language that has string manipulation abilities. I'm personally trying to use ActionScript 3, but the problem itself is not language-specific. Commented Aug 19, 2011 at 22:52
  • @Edward K Huang but languages are OS dependent. I could tell you to use perl p.a. but under windows, it may work not exactly the same way and would be a huge overhead. Thats why i'm asking for the language =) Commented Aug 19, 2011 at 23:20

1 Answer 1

3

There is something known as the Levenshtein distance that tells you how many changes are needed to go from one string to another and there are many C# implementations, many other languages too.

Here's the wiki:

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

Edit: As TheHorse has indicated, the Levenshtein distance doesn't understand Shift changes, but there is an improved algorithm:

Damerau-Levenshtein distance

Sign up to request clarification or add additional context in comments.

3 Comments

Levenshtein distance have no SHIFT operation.
Sure it does, well, it understands substitution anyway ... and that's the example Edward has represented. An improved algorith is Damerau Levenshtein which supports transposition as well as addition, deletion and substitution: en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance
Actually, sorry you're correct, substitution isn't the same as transposition. I'll update my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.