Question
In Python, implement the pseudocode algorithm for edit distance. The algorithm has different editing operations carry different weights as follows: insertion weighs 3, deletion weighs
In Python, implement the pseudocode algorithm for edit distance. The algorithm has different editing operations carry different weights as follows: insertion weighs 3, deletion weighs 6, and replacement weighs 5. Skeleton code is provided (may have some minor typos).
PSEUDOCODE FOR ALGORITHM
SKELETON CODE
edit_distance(s1, s2, L1, L2): # Create a table to store the results of subproblems dp = [[0 for j in range(L2+1)] for i in range(L1+1)]
# Initialize costs insert_cost = 3 delete_cost= 6 replace_cost = 5
# Initialize the table for i in range(L1+1): dp[i][0] = i for j in range(L2+1): dp[0][j] = j
# Populate the table using dynamic programming for i in range(L1+1): for j in range(L2+1):
#Put code here
# Return the edit distance return dp[L1][L2]
print(edit_distance("geeks", "forgeeks", len("geeks"), len("forgeeks"))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started