Complete the code to initialize the base case for the first string length in the edit distance matrix.
for (int i = 0; i <= m; i++) { dp[i][0] = [1]; }
The first column of the matrix represents converting the first i characters of string1 to an empty string, which requires i deletions.
Complete the code to initialize the base case for the first string length in the edit distance matrix for the second string.
for (int j = 0; j <= n; j++) { dp[0][j] = [1]; }
The first row of the matrix represents converting an empty string to the first j characters of string2, which requires j insertions.
Fix the error in the condition that checks if characters at positions i-1 and j-1 are the same.
if (s1[i - 1] [1] s2[j - 1]) { dp[i][j] = dp[i - 1][j - 1]; } else { dp[i][j] = 1 + min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])); }
The condition must check if the characters are equal using '=='. Using '=' assigns a value and causes an error.
Fill both blanks to complete the min function calls to find the minimum edit distance operation cost.
dp[i][j] = 1 + min(dp[i - 1][j], min(dp[i][j - 1], dp[i [1]][j [2]]));
The last term compares dp[i-1][j-1], so the blanks must be '-' and '1' respectively.
Fill all three blanks to complete the function signature and return statement for the Levenshtein distance function.
[1] levenshtein_distance([2] s1, [3] s2) { int m = strlen(s1); int n = strlen(s2); int dp[m + 1][n + 1]; // initialization and computation code here return dp[m][n]; }
The function returns an int distance and takes two constant character pointers as input strings.