Skip to content

Commit 0815019

Browse files
authored
min_edit_distance
Initial File
1 parent de69507 commit 0815019

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

min_edit distance

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def min_edit_distance(str1,str2):
2+
m=len(str1)
3+
n=len(str2)
4+
dp=[[0 for x in range(n+1)] for y in range(m+1)]
5+
for i in range(m+1):
6+
for j in range(n+1):
7+
if(i==0):
8+
dp[i][j]=j
9+
elif(j==0):
10+
dp[i][j]=i
11+
elif(str1[i-1]==str2[j-1]):
12+
dp[i][j]=dp[i-1][j-1]
13+
else:
14+
dp[i][j]= 1+ min(dp[i][j-1],dp[i-1][j],dp[i-1][j-1])
15+
return dp[i][j]
16+
17+
str1="data"
18+
str2="dent"
19+
print(min_edit_distance(str1,str2))
20+
21+
22+

0 commit comments

Comments
 (0)