Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the DP table with zeros.
DSA Python
dp = [[[1] for _ in range(len(word2) + 1)] for _ in range(len(word1) + 1)]
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 causes wrong initial distances.
Using None or empty string causes type errors.
✗ Incorrect
The DP table should be initialized with zeros to start counting edit distances.
2fill in blank
mediumComplete the code to fill the first row of the DP table with increasing numbers.
DSA Python
for j in range(1, len(word2) + 1): dp[0][j] = dp[0][j-1] [1] 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication changes the meaning.
Using integer division causes zero increments.
✗ Incorrect
Each cell in the first row increases by 1 to represent insertions.
3fill in blank
hardFix the error in the condition to check if characters are the same.
DSA Python
if word1[i-1] [1] word2[j-1]:
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' causes wrong cost calculation.
Using '>' or '<' is not meaningful for characters here.
✗ Incorrect
We check if characters are equal to decide if substitution cost is zero.
4fill in blank
hardFill both blanks to compute the minimum edit distance for dp[i][j].
DSA Python
dp[i][j] = min(dp[i-1][j] + [1], dp[i][j-1] + [2], dp[i-1][j-1] + cost)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or cost for insertion/deletion is incorrect.
Using 2 overestimates the cost.
✗ Incorrect
Insertion and deletion cost 1 each, so add 1 to those moves.
5fill in blank
hardFill all three blanks to set the substitution cost correctly.
DSA Python
cost = [1] if word1[i-1] [2] word2[j-1] else [3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' in condition reverses logic.
Using cost 2 or 0 incorrectly.
✗ Incorrect
If characters are equal, cost is 0; else cost is 1 for substitution.
