We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent de69507 commit 0815019Copy full SHA for 0815019
1 file changed
min_edit distance
@@ -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