1

I was just going over some questions but I got stuck at a Levenshtein edit distance question.

So the first part of the question was:

What is the Levenshtein edit distance between the strings STRONGEST and TRAINERS?

Which I calculated as 6. But the next question I could not get is

Let d be the edit distance found in part (so 6). How many different sets of dedits’ (insertions, deletions, or substitutions) are there that will change the string STRONGEST into the string TRAINERS?

Could anyone explain how I could find how many different sets exists here and how you arrived with the solution?

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
Min
  • 528
  • 1
  • 7
  • 26
  • 1
    Define the usual matrix. Every path from the top left corner to the bottom right corner represents a sequence of edits that transforms `STRONGEST` into `TRAINERS`. Check [Wikipedia](https://en.wikipedia.org/wiki/Levenshtein_distance), it explains the algorithm in detail. I'm talking about the table as seen in [this demo](http://www.let.rug.nl/kleiweg/lev/). – Zabuzard Jun 18 '18 at 10:37
  • 1
    So the question can be rephrased to how many paths exist from top left to bottom right. Which are infinitely many if you allow cycles (insert, delete, insert, delete, ..., correct sequence). However, I think the question is more about the **shortest paths**, not non-optimal. So you need to check how many paths you find on the matrix that arrive with the same final result (shortest cost). – Zabuzard Jun 18 '18 at 11:24
  • alright thanks i got 8 different sets. hope it's right – Min Jun 18 '18 at 11:43

1 Answers1

1

If you have used memoization table approach for the first problem, just go to the right-bottom corner of table (where you get minimum edit distance) and trace back all possible paths of minimum edits. All these paths will give you different sets of edits. For reference on how to trace back, you could see this solution to problem of printing LCS of two strings.

You could also refer to my comment on the above mentioned page.

Gaurav Singh
  • 456
  • 6
  • 17