I have a Java program that calculates the Levenshtein distance between two strings. I use this method to do it:
public static int levDistance(String s, int len_s, String t, int len_t) {
if (len_s == 0)
return len_t;
if (len_t == 0)
return len_s;
int cost = 0;
if (s.charAt(len_s - 1) == t.charAt(len_t - 1))
cost = 0;
else
cost = 1;
return Math.min(Math.min(
levDistance(s, len_s - 1, t, len_t) + 1,
levDistance(s, len_s, t, len_t - 1) + 1),
levDistance(s, len_s - 1, t, len_t - 1) + cost);
}
As the title suggests, I need to get every step in this procedure. I don't really care how it's returned (could be newline-separated, in an arraylist, etc.) or in what order it's in, only that one character is changed at each step.
Examples:
distance("saturday", "sauterdai"); -> "saturday", "sauterday", "sauterdai"
distance("algorithm", "algurthm") -> "algorithm", "algorthm", "algurithm"
distance("stackoverflow", "mathoverflow") -> "stackoverflow", "tackoverflow", "tckoverflow", "tkoverflow", "toverflow", "mtoverflow", "matoverflow", "mathoverflow"