Tôi đang tìm hiểu về khoảng cách chỉnh sửa lần đầu tiên và chỉ được mã hóa trong một vài tháng. Tôi đang cố gắng sửa đổi thuật toán sao cho các hoạt động chỉnh sửa khác nhau mang các trọng số khác nhau như sau: chèn nặng 20, xóa nặng 20 và thay thế nặng 5.
Tôi đã có thể thực hiện mã cơ bản tính toán khoảng cách chỉnh sửa tối thiểu nếu tất cả các hoạt động có trọng lượng bằng nhau [khoảng cách Levenshtein]. Nhưng làm thế nào một người sẽ thực hiện nó nếu chúng khác nhau như đã nêu ở trên? Đây là những gì tôi có vào lúc này:
str1="algorithms"
str2="alligator"
m=len[str1]
n=len[str2]
def editdistance[str1, str2, m, n]:
table=[[0 for x in range[n+1]] for x in range[m+1]]
for i in range[m+1]:
for j in range[n+1]:
if i==0:
table[i][j]=j
elif j==0:
table[i][j]=i
elif str1[i-1]==str2[j-1]:
table[i][j]=table[i-1][j-1]
else:
table[i][j] = min[20+table[i][j-1], 20+table[i-1][j], 5+table[i-1][j-1]]
return table[m][n]
print[editdistance[str1, str2, m, n]]
Đầu ra là 46, rõ ràng là sai vì câu trả lời phải là bội số của 5. Tôi còn thiếu gì ở đây? Mọi sự trợ giúp sẽ rất được trân trọng.
Cho hai chuỗi Str1 và Str2 trở xuống các hoạt động có thể được thực hiện trên STR1. Tìm số lượng chỉnh sửa tối thiểu [hoạt động] cần thiết để chuyển đổi ‘str1, thành‘ str2, & nbsp; & nbsp;
- Chèn
- Loại bỏ
- Thay thế
Tất cả các hoạt động trên có chi phí bằng nhau. & NBSP;
Examples:
Đầu vào: & nbsp; & nbsp; str1 = Hồi Geek, str2 = đầu ra của Gesek Gesek: & nbsp; str1 = “geek”, str2 = “gesek”
Output: 1
Explanation: We can convert str1 into str2 by inserting a ‘s’.Đầu vào: & nbsp; str1 = người Cat Cat, str2 = đầu ra cắt giảm: & nbsp; 1Explanation: Chúng ta có thể chuyển đổi str1 thành str2 bằng cách thay thế ’a, bằng’ u. str1 = “cat”, str2 = “cut”
Output: 1
Explanation: We can convert str1 into str2 by replacing ‘a’ with ‘u’.Đầu vào: & nbsp; & nbsp; str1 = Hồi Chủ nhật, str2 = đầu ra thứ bảy của Saturday: & nbsp; 3Explanation: ba nhân vật cuối cùng và đầu tiên giống nhau. & nbsp; về cơ bản, chúng tôi cần phải chuyển đổi các ứng dụng của UN. & nbsp; Điều này có thể được thực hiện bằng cách sử dụng dưới ba hoạt động. Thay thế ‘n, bằng‘ r, chèn t, chèn một str1 = “sunday”, str2 = “saturday”
Output: 3
Explanation: Last three and first characters are same. We basically need to convert “un” to “atur”. This can be done using below three operations. Replace ‘n’ with ‘r’, insert t, insert a
Các biểu tượng con trong trường hợp này là gì? đang đi qua. & nbsp; & nbsp;
The idea is to process all characters one by one starting from either from left or right sides of both strings.
Let us traverse from right corner, there are two possibilities for every pair of character being traversed.
m: Length of str1 [first string] n: Length of str2 [second string]
- Nếu các ký tự cuối cùng của hai chuỗi là giống nhau, không có gì nhiều để làm. Bỏ qua các ký tự cuối cùng và nhận được số lượng cho các chuỗi còn lại. Vì vậy, chúng tôi tái diễn cho độ dài M-1 và N-1.
- Khác [nếu các ký tự cuối cùng không giống nhau], chúng tôi xem xét tất cả các hoạt động trên ‘str1, hãy xem xét cả ba hoạt động trên ký tự cuối cùng của chuỗi đầu tiên, tính toán chi phí tối thiểu cho cả ba hoạt động và mất tối thiểu ba giá trị. & Nbsp;
- Chèn: Tái phát cho M và N-1
- Xóa: Tái phát cho M-1 và N
- Thay thế: Tái phát cho M-1 và N-1
Dưới đây là thực hiện giải pháp đệ quy ngây thơ ở trên.
C++
#include
using
namespace
std;
int
min[
int
x,
int
m: Length of str1 [first string] n: Length of str2 [second string]1
int
m: Length of str1 [first string] n: Length of str2 [second string]3
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]5
int
m: Length of str1 [first string] n: Length of str2 [second string]7
int
m: Length of str1 [first string] n: Length of str2 [second string]9
int
#include
1#include
2
#include
3#include
4 #include
5
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
8#include
3#include
4 using
1
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
using
4#include
3#include
4 using
7
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
namespace
0#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
namespace
3namespace
4namespace
5
namespace
6namespace
7
namespace
6namespace
9
std;
0std;
1
std;
2std;
3
std;
4
int
std;
6
#include
2
#include
3std;
9int
0int
1
#include
3int
3int
4int
1
#include
3int
7
int
8int
9
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
min[
2std;
4
Java
min[
4 min[
5
#include
3min[
7 int
min[
int
x,
int
m: Length of str1 [first string] n: Length of str2 [second string]1
int
int
5#include
3#include
2
#include
6#include
4 x,
0
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
3#include
6#include
4 x,
6
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
9#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]04
#include
3std;
4
#include
3min[
7 int
m: Length of str1 [first string] n: Length of str2 [second string]10
int
m: Length of str1 [first string] n: Length of str2 [second string]12
m: Length of str1 [first string] n: Length of str2 [second string]13
int
#include
1#include
3#include
2
#include
6#include
4
m: Length of str1 [first string] n: Length of str2 [second string]20
m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]22
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
8#include
6#include
4
m: Length of str1 [first string] n: Length of str2 [second string]28
m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]22
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
using
4#include
6#include
4
m: Length of str1 [first string] n: Length of str2 [second string]36
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]38
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]40
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]43
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]45
namespace
3std;
3#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
namespace
3x,
1
m: Length of str1 [first string] n: Length of str2 [second string]52
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]54
m: Length of str1 [first string] n: Length of str2 [second string]55
m: Length of str1 [first string] n: Length of str2 [second string]43
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]58
m: Length of str1 [first string] n: Length of str2 [second string]55
m: Length of str1 [first string] n: Length of str2 [second string]43
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]62
m: Length of str1 [first string] n: Length of str2 [second string]63
m: Length of str1 [first string] n: Length of str2 [second string]64
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]66
m: Length of str1 [first string] n: Length of str2 [second string]67
std;
3#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]72
min[
7 m: Length of str1 [first string] n: Length of str2 [second string]74
m: Length of str1 [first string] n: Length of str2 [second string]75
#include
3#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]79
int
0int
1#include
6
m: Length of str1 [first string] n: Length of str2 [second string]83
int
4int
1#include
6
m: Length of str1 [first string] n: Length of str2 [second string]87
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]89
#include
3std;
4
std;
4
Python3
m: Length of str1 [first string] n: Length of str2 [second string]93
m: Length of str1 [first string] n: Length of str2 [second string]94
#include
3#include
4
m: Length of str1 [first string] n: Length of str2 [second string]97
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
01#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
04#include
3#include
4 #include
07
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
01#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
14#include
3#include
4 #include
17#include
18namespace
3__
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
29#include
18namespace
3#include
32#include
18namespace
3m: Length of str1 [first string] n: Length of str2 [second string]22
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
namespace
3 #include
39 #include
40#include
41__#include
45#include
29#include
18namespace
3#include
49
#include
45#include
29#include
18namespace
3#include
32#include
18namespace
3#include
57
#include
45
m: Length of str1 [first string] n: Length of str2 [second string]22
#include
60
m: Length of str1 [first string] n: Length of str2 [second string]98
int
0#include
63
m: Length of str1 [first string] n: Length of str2 [second string]98
int
4#include
66 #include
67#include
68#include
69#include
68#include
71
C#
using
#include
73
min[
4 #include
75
#include
3min[
7 int
min[
int
x,
int
m: Length of str1 [first string] n: Length of str2 [second string]1
int
int
5#include
3#include
2
#include
6#include
4 x,
0
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
3#include
6#include
4 x,
6
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
9#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]04
#include
3std;
4
#include
3min[
7 int
m: Length of str1 [first string] n: Length of str2 [second string]10
int
m: Length of str1 [first string] n: Length of str2 [second string]12
m: Length of str1 [first string] n: Length of str2 [second string]13
int
#include
1#include
3#include
2
#include
6#include
4 x,
0
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
8#include
6#include
4
m: Length of str1 [first string] n: Length of str2 [second string]28
m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]22
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
using
4#include
6#include
4
m: Length of str1 [first string] n: Length of str2 [second string]36
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]38
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]40
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]43
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]45
namespace
3std;
3#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
namespace
3x,
1namespace
5
m: Length of str1 [first string] n: Length of str2 [second string]55
namespace
7m: Length of str1 [first string] n: Length of str2 [second string]55
namespace
9m: Length of str1 [first string] n: Length of str2 [second string]63
std;
1m: Length of str1 [first string] n: Length of str2 [second string]67
std;
3#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]72
min[
7 m: Length of str1 [first string] n: Length of str2 [second string]74
m: Length of str1 [first string] n: Length of str2 [second string]75
#include
3#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]79
int
0int
1#include
6
m: Length of str1 [first string] n: Length of str2 [second string]87
#include
6using
67
x,
1using
69
#include
3std;
4
std;
4
m: Length of str1 [first string]
n: Length of str2 [second string]
93 m: Length of str1 [first string]
n: Length of str2 [second string]
94
using
73
#include
3#include
4
m: Length of str1 [first string] n: Length of str2 [second string]97
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
01using
80using
81using
77using
83
m: Length of str1 [first string] n: Length of str2 [second string]22
#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
04#include
3#include
4 #include
07
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
01#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
14#include
3#include
4 #include
17#include
18namespace
3__
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
29#include
18namespace
3#include
32#include
18namespace
3m: Length of str1 [first string] n: Length of str2 [second string]22
#include
3#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
using
75using
76using
777____378m: Length of str1 [first string] n: Length of str2 [second string]62
namespace
24using
81 namespace
26using
83 namespace
28
#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
namespace
33using
76using
777____378m: Length of str1 [first string] n: Length of str2 [second string]62
namespace
38using
81using
77 ____383 namespace
42
#include
45using
75using
76using
77using
78
m: Length of str1 [first string] n: Length of str2 [second string]62
namespace
38using
81 namespace
26using
83
m: Length of str1 [first string] n: Length of str2 [second string]54
#include
45using
75using
76using
77using
78
m: Length of str1 [first string] n: Length of str2 [second string]62
namespace
38using
81 namespace
26using
83 namespace
64
std;
4
using
76 namespace
67int
0int
1
using
78 namespace
67int
4int
1
namespace
74 using
75using
76using
77 ____378using
777____480using
88using
76namespace
83
namespace
38namespace
80using
88using
78namespace
88
namespace
89
JavaScript
namespace
90
using
74 namespace
92
#include
2
#include
3#include
4 x,
0
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
3#include
3#include
4 x,
6
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
9#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]04
std;
4
using
74 std;
13
#include
2
#include
3#include
4 #include
5
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
8#include
3#include
4 using
1
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
using
4#include
3#include
4 using
7
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
namespace
0#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
std;
35#include
3std;
37
#include
6namespace
7
#include
6std;
41
std;
4
std;
43int
0int
1
std;
46int
4int
1
std;
49
std;
50std;
51
std;
52
Độ phức tạp thời gian của giải pháp trên là theo cấp số nhân. Trong trường hợp xấu nhất, cuối cùng chúng ta có thể thực hiện các hoạt động O [3M]. Trường hợp xấu nhất xảy ra khi không có ký tự nào của hai chuỗi phù hợp. Dưới đây là sơ đồ cuộc gọi đệ quy cho trường hợp xấu nhất. & NBSP; Không gian phụ trợ: O [1], vì không có thêm không gian được sử dụng.time complexity of above solution is exponential. In worst case, we may end up doing O[3m] operations. The worst case happens when none of characters of two strings match. Below is a recursive call diagram for worst case.
Auxiliary Space: O[1], because no extra space is utilized.
Chúng ta có thể thấy rằng nhiều vấn đề phụ được giải quyết, ví dụ, ví dụ, ed [2, 2] được gọi là ba lần. Vì các vấn đề nhỏ được gọi là lại, vấn đề này có thuộc tính SubProplips chồng chéo. Vì vậy, chỉnh sửa vấn đề khoảng cách có cả hai thuộc tính [xem điều này và điều này] của một vấn đề lập trình động. Giống như các vấn đề lập trình động [DP] điển hình khác, các phép tính lại của cùng một biểu tượng con có thể tránh được bằng cách xây dựng một mảng tạm thời lưu trữ kết quả của các vấn đề phụ.
C++
#include
using
namespace
std;
int
min[
int
x,
int
m: Length of str1 [first string] n: Length of str2 [second string]1
int
m: Length of str1 [first string] n: Length of str2 [second string]3
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]5
int
std;
68int
m: Length of str1 [first string] n: Length of str2 [second string]9
int
#include
1#include
2
#include
3int
std;
76
#include
3std;
78 using
88int
std;
81
#include
6std;
78 using
88int
std;
86
x,
1#include
4 std;
89
std;
90std;
91
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 std;
95std;
90std;
97
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 int
01std;
90int
03
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
std;
90int
07
int
08int
09
using
80int
11
namespace
24int
13
namespace
24int
15
#include
6std;
4
#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
int
22std;
4
int
std;
6
#include
2
#include
3std;
9int
0int
1
#include
3int
3int
4int
1
#include
3int
36
int
37int
9
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
min[
2std;
4
Java
min[
4 min[
5
#include
3min[
7 int
min[
int
x,
int
m: Length of str1 [first string] n: Length of str2 [second string]1
int
int
5#include
3#include
2
#include
6#include
4 x,
0
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
3#include
6#include
4 x,
6
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
9#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]04
#include
3std;
4
#include
3min[
7 int
int
79int
m: Length of str1 [first string] n: Length of str2 [second string]12
std;
0____6 #include
1
#include
3#include
2
#include
6int
int
89int
90 int
__692
#include
6std;
78 using
88int
min[
01
m: Length of str1 [first string] n: Length of str2 [second string]21
min[
03x,
1std;
78 using
88int
min[
08
m: Length of str1 [first string] n: Length of str2 [second string]21
min[
10std;
90#include
4 min[
13
m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]22
int
08std;
91
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 min[
21m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]22
int
08std;
97
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 min[
29namespace
3m: Length of str1 [first string] n: Length of str2 [second string]22
min[
32min[
33namespace
3
m: Length of str1 [first string] n: Length of str2 [second string]40
int
08min[
37namespace
3min[
39namespace
3int
96
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
int
08min[
45namespace
3
min[
47min[
48namespace
3min[
50
min[
51min[
52namespace
3min[
54
min[
51min[
52namespace
3min[
58
min[
59min[
60namespace
3min[
62
x,
1std;
4
#include
6std;
4
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
int
22#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]72
min[
7 m: Length of str1 [first string] n: Length of str2 [second string]74
m: Length of str1 [first string] n: Length of str2 [second string]75
#include
3#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]79
int
0int
1#include
6
m: Length of str1 [first string] n: Length of str2 [second string]83
int
4int
1#include
6min[
88
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]89
#include
3std;
4
min[
93
Python3
m: Length of str1 [first string] n: Length of str2 [second string]93
min[
95#include
3min[
97 ____198 min[
99
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
3std;
78 int
19int
03 int
04int
13__
#include
6std;
78 int
28int
03 int
04int
05__
x,
1#include
4 int
19
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
01std;
90int
43
m: Length of str1 [first string] n: Length of str2 [second string]98
int
45
x,
1int
47 int
28
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
01std;
90int
43
m: Length of str1 [first string] n: Length of str2 [second string]98
int
56x,
1int
47 int
59#include
18namespace
3__
std;
90int
43
m: Length of str1 [first string] n: Length of str2 [second string]98
int
72#include
18namespace
3int
75#include
18namespace
3min[
58x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
01std;
90int
43
m: Length of str1 [first string] n: Length of str2 [second string]98
namespace
3 #include
39 #include
40__int
92int
72#include
18namespace
3int
96
Các
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
07#include
60
m: Length of str1 [first string] n: Length of str2 [second string]98
int
0#include
63
m: Length of str1 [first string] n: Length of str2 [second string]98
int
4#include
66x,
15#include
68#include
69#include
68#include
71
C#
using
#include
73
min[
4 #include
75
#include
3min[
7 int
min[
int
x,
int
m: Length of str1 [first string] n: Length of str2 [second string]1
int
int
5#include
3#include
2
#include
6#include
4 x,
0
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
3#include
6#include
4 x,
6
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
9#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]04
#include
3std;
4
#include
3min[
7 int
int
79int
m: Length of str1 [first string] n: Length of str2 [second string]12
std;
0____6 #include
1
#include
3#include
2
#include
6int
x,
68int
90 int
x,
71
#include
6std;
78 using
88int
std;
81
x,
1std;
78 using
88int
std;
86
std;
90#include
4 std;
89
int
08x,
86
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 std;
95int
08x,
92
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 int
01int
08x,
98
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
int
08
m: Length of str1 [first string] n: Length of str2 [second string]002
min[
47
m: Length of str1 [first string] n: Length of str2 [second string]004
min[
51
m: Length of str1 [first string] n: Length of str2 [second string]006
min[
51
m: Length of str1 [first string] n: Length of str2 [second string]008
m: Length of str1 [first string] n: Length of str2 [second string]009
m: Length of str1 [first string] n: Length of str2 [second string]010
x,
1std;
4
#include
6std;
4
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]017
#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]72
min[
7 m: Length of str1 [first string] n: Length of str2 [second string]74
using
55#include
3#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]79
int
0int
1#include
6
m: Length of str1 [first string] n: Length of str2 [second string]83
int
4int
1#include
6
m: Length of str1 [first string] n: Length of str2 [second string]036
m: Length of str1 [first string] n: Length of str2 [second string]037
m: Length of str1 [first string] n: Length of str2 [second string]038
#include
3std;
4
std;
4
PHP
using
73
using
74
m: Length of str1 [first string] n: Length of str2 [second string]044
using
76using
77 ____378m: Length of str1 [first string] n: Length of str2 [second string]62
int
08using
81using
77using
83
m: Length of str1 [first string] n: Length of str2 [second string]22
#include
2
std;
78 using
88
m: Length of str1 [first string] n: Length of str2 [second string]057 ____1058
m: Length of str1 [first string] n: Length of str2 [second string]057
m: Length of str1 [first string] n: Length of str2 [second string]065
Is
#include
3#include
2
#include
6#include
4 using
88
m: Length of str1 [first string] n: Length of str2 [second string]057
using
90Các
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4using
88m: Length of str1 [first string] n: Length of str2 [second string]069
using
90x,
1
m: Length of str1 [first string] n: Length of str2 [second string]085
namespace
08m: Length of str1 [first string] n: Length of str2 [second string]057
m: Length of str1 [first string] n: Length of str2 [second string]088
m: Length of str1 [first string] n: Length of str2 [second string]069
m: Length of str1 [first string] n: Length of str2 [second string]090
m: Length of str1 [first string] n: Length of str2 [second string]057
m: Length of str1 [first string] n: Length of str2 [second string]062
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4using
88using
76____408__Các
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
6#include
2
Các
m: Length of str1 [first string] n: Length of str2 [second string]150
m: Length of str1 [first string] n: Length of str2 [second string]085
namespace
08m: Length of str1 [first string] n: Length of str2 [second string]057
m: Length of str1 [first string] n: Length of str2 [second string]130__1069
m: Length of str1 [first string] n: Length of str2 [second string]156
m: Length of str1 [first string] n: Length of str2 [second string]150
m: Length of str1 [first string] n: Length of str2 [second string]085
namespace
08m: Length of str1 [first string] n: Length of str2 [second string]057
m: Length of str1 [first string] n: Length of str2 [second string]130
m: Length of str1 [first string] n: Length of str2 [second string]069
m: Length of str1 [first string] n: Length of str2 [second string]163
#include
6std;
4
#include
3std;
4
std;
4
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]085
namespace
08using
81m: Length of str1 [first string] n: Length of str2 [second string]088
using
83m: Length of str1 [first string] n: Length of str2 [second string]175
std;
4
using
76 namespace
67int
0int
1
using
78 namespace
67int
4int
1
namespace
74
m: Length of str1 [first string] n: Length of str2 [second string]044
using
76using
77 ____378using
777____480using
88using
76namespace
83m: Length of str1 [first string] n: Length of str2 [second string]195
namespace
80using
88using
78namespace
88namespace
89
JavaScript
namespace
90
using
74
m: Length of str1 [first string] n: Length of str2 [second string]203
#include
2
#include
3#include
4 x,
0
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
3#include
6#include
4 x,
6
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
x,
9#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]04
std;
4
using
74
m: Length of str1 [first string] n: Length of str2 [second string]224
#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]227
int
90 m: Length of str1 [first string] n: Length of str2 [second string]229
#include
6std;
78
m: Length of str1 [first string] n: Length of str2 [second string]232
#include
6#include
2
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]236
int
90 m: Length of str1 [first string] n: Length of str2 [second string]238
x,
1std;
78
m: Length of str1 [first string] n: Length of str2 [second string]241
x,
1#include
2
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]245
x,
1std;
4
#include
6std;
4
#include
6std;
78
m: Length of str1 [first string] n: Length of str2 [second string]252
x,
1std;
78
m: Length of str1 [first string] n: Length of str2 [second string]255
std;
90#include
4 std;
89
int
08std;
91
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 std;
95int
08std;
97
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 m: Length of str1 [first string] n: Length of str2 [second string]270
min[
32
m: Length of str1 [first string] n: Length of str2 [second string]272
int
08int
03
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]01
int
08
m: Length of str1 [first string] n: Length of str2 [second string]278
min[
47int
11
min[
51int
13
min[
51
m: Length of str1 [first string] n: Length of str2 [second string]284
min[
59
m: Length of str1 [first string] n: Length of str2 [second string]286
x,
1std;
4
#include
6std;
4
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
int
22std;
4
std;
43int
0int
1
std;
46int
4int
1
m: Length of str1 [first string] n: Length of str2 [second string]301
m: Length of str1 [first string] n: Length of str2 [second string]302
std;
52
Độ phức tạp về thời gian: O [M x N] & NBSP; Không gian phụ trợ: O [M x N] O[m x n]
Auxiliary Space: O[m x n]
Giải pháp phức tạp không gian: Trong phương pháp được đưa ra trên, chúng tôi yêu cầu không gian O [M x N]. Điều này sẽ không phù hợp nếu độ dài của chuỗi lớn hơn 2000 vì nó chỉ có thể tạo mảng 2D 2000 x 2000. Để lấp đầy một hàng trong mảng DP, chúng tôi chỉ yêu cầu một hàng trên trên. Ví dụ: nếu chúng ta đang điền vào các hàng I = 10 trong mảng DP, chúng ta chỉ yêu cầu các giá trị của hàng thứ 9. Vì vậy, chúng tôi chỉ cần tạo một mảng DP có chiều dài 2 x str1. Cách tiếp cận này làm giảm sự phức tạp không gian. Đây là việc thực hiện C ++ của vấn đề nêu trên: In the above-given method we require O[m x n] space. This will not be suitable if the length of strings is greater than 2000 as it can only create 2D array of 2000 x 2000. To fill a row in DP array we require only one row the upper row. For example, if we are filling the i = 10 rows in DP array we require only values of 9th row. So we simply create a DP array of 2 x str1 length. This approach reduces the space complexity. Here is the C++ implementation of the above-mentioned problem
C++
#include
using
namespace
std;
m: Length of str1 [first string] n: Length of str2 [second string]74
m: Length of str1 [first string] n: Length of str2 [second string]309
#include
2
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]313
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]316
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]319
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]321
m: Length of str1 [first string] n: Length of str2 [second string]32222323
m: Length of str1 [first string] n: Length of str2 [second string]324
#include
3std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]329
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]331
#include
3std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]336
#include
6std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]341
x,
1#include
4 std;
95
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]346
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 m: Length of str1 [first string] n: Length of str2 [second string]350
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]352
x,
1std;
4
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
2std;
90
m: Length of str1 [first string] n: Length of str2 [second string]359
min[
59
m: Length of str1 [first string] n: Length of str2 [second string]361
m: Length of str1 [first string] n: Length of str2 [second string]362
m: Length of str1 [first string] n: Length of str2 [second string]363
x,
1std;
4
#include
6std;
4
#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]371
std;
4
int
std;
6
#include
2
#include
3std;
9
m: Length of str1 [first string] n: Length of str2 [second string]378
int
1#include
3int
3
m: Length of str1 [first string] n: Length of str2 [second string]382
int
1#include
3
m: Length of str1 [first string] n: Length of str2 [second string]385
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
min[
2std;
4
Java
m: Length of str1 [first string] n: Length of str2 [second string]390
m: Length of str1 [first string] n: Length of str2 [second string]391
min[
4
m: Length of str1 [first string] n: Length of str2 [second string]393
#include
2
min[
7
m: Length of str1 [first string] n: Length of str2 [second string]74
m: Length of str1 [first string] n: Length of str2 [second string]397
#include
2
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]313
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]316
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]319
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]321
m: Length of str1 [first string] n: Length of str2 [second string]32222323
m: Length of str1 [first string] n: Length of str2 [second string]324
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]423
m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]425
#include
3std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]329
#include
3#include
2
#include
3std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]336
#include
6#include
2
#include
6std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]341
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]450
m: Length of str1 [first string] n: Length of str2 [second string]411
m: Length of str1 [first string] n: Length of str2 [second string]452
x,
1#include
4 std;
95
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]450
m: Length of str1 [first string] n: Length of str2 [second string]411
m: Length of str1 [first string] n: Length of str2 [second string]464
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]466
m: Length of str1 [first string] n: Length of str2 [second string]411
min[
39namespace
3int
96x,
1std;
4
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
2min[
59
m: Length of str1 [first string] n: Length of str2 [second string]361
min[
59
m: Length of str1 [first string] n: Length of str2 [second string]487
m: Length of str1 [first string] n: Length of str2 [second string]411
min[
39namespace
3m: Length of str1 [first string] n: Length of str2 [second string]491
m: Length of str1 [first string] n: Length of str2 [second string]362
m: Length of str1 [first string] n: Length of str2 [second string]493
namespace
3m: Length of str1 [first string] n: Length of str2 [second string]466
m: Length of str1 [first string] n: Length of str2 [second string]411
min[
39namespace
3m: Length of str1 [first string] n: Length of str2 [second string]499
x,
1std;
4
#include
6std;
4
#include
3std;
4
int
std;
6
std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
min[
2#include
2
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]79
m: Length of str1 [first string] n: Length of str2 [second string]378
int
1#include
3
m: Length of str1 [first string] n: Length of str2 [second string]83
m: Length of str1 [first string] n: Length of str2 [second string]382
int
1#include
3
m: Length of str1 [first string] n: Length of str2 [second string]385
std;
4
std;
4
Python3
Java
m: Length of str1 [first string] n: Length of str2 [second string]390
m: Length of str1 [first string] n: Length of str2 [second string]391
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]538
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
68m: Length of str1 [first string] n: Length of str2 [second string]541
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]543______198
std;
2std;
78 int
28int
03 int
04using
88
m: Length of str1 [first string] n: Length of str2 [second string]411
m: Length of str1 [first string] n: Length of str2 [second string]562
#include
3std;
78 int
19______803
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]423
m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]577
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]579
#include
3std;
78 int
19______803
#include
6std;
78 int
28______803
x,
1#include
4
m: Length of str1 [first string] n: Length of str2 [second string]604
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
int
25std;
90
m: Length of str1 [first string] n: Length of str2 [second string]610
m: Length of str1 [first string] n: Length of str2 [second string]611
m: Length of str1 [first string] n: Length of str2 [second string]411
m: Length of str1 [first string] n: Length of str2 [second string]613
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]579
x,
1int
47
m: Length of str1 [first string] n: Length of str2 [second string]618
#include
18 namespace
3__std;
90
m: Length of str1 [first string] n: Length of str2 [second string]610
m: Length of str1 [first string] n: Length of str2 [second string]611
m: Length of str1 [first string] n: Length of str2 [second string]411
m: Length of str1 [first string] n: Length of str2 [second string]613__
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
01std;
90
m: Length of str1 [first string] n: Length of str2 [second string]610
m: Length of str1 [first string] n: Length of str2 [second string]611
m: Length of str1 [first string] n: Length of str2 [second string]411
m: Length of str1 [first string] n: Length of str2 [second string]613__
std;
50#include
40
m: Length of str1 [first string] n: Length of str2 [second string]666
m: Length of str1 [first string] n: Length of str2 [second string]611
m: Length of str1 [first string] n: Length of str2 [second string]411
m: Length of str1 [first string] n: Length of str2 [second string]640______
m: Length of str1 [first string] n: Length of str2 [second string]150
m: Length of str1 [first string] n: Length of str2 [second string]634
m: Length of str1 [first string] n: Length of str2 [second string]8
#include
3#include
66
m: Length of str1 [first string] n: Length of str2 [second string]686
m: Length of str1 [first string] n: Length of str2 [second string]611
m: Length of str1 [first string] n: Length of str2 [second string]411
m: Length of str1 [first string] n: Length of str2 [second string]689
#include
4
m: Length of str1 [first string] n: Length of str2 [second string]691
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]694
#include
01#include
3#include
60
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]378
#include
3#include
63
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]382
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]705
C#
using
#include
73
min[
4
m: Length of str1 [first string] n: Length of str2 [second string]393
#include
2
min[
7
m: Length of str1 [first string] n: Length of str2 [second string]74
m: Length of str1 [first string] n: Length of str2 [second string]397
#include
2
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]717
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]720
#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]723
int
90 int
m: Length of str1 [first string] n: Length of str2 [second string]726
#include
3std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]329
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]733
#include
3std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]738
#include
3#include
2
#include
6std;
78 using
88int
m: Length of str1 [first string] n: Length of str2 [second string]745
#include
6#include
2
x,
1#include
4 std;
95
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]752
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 m: Length of str1 [first string] n: Length of str2 [second string]756
x,
1#include
2
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]760
x,
1std;
4
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
2std;
90
m: Length of str1 [first string] n: Length of str2 [second string]767
min[
59
m: Length of str1 [first string] n: Length of str2 [second string]769
m: Length of str1 [first string] n: Length of str2 [second string]362
m: Length of str1 [first string] n: Length of str2 [second string]771
x,
1std;
4
#include
6std;
4
#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]779
m: Length of str1 [first string] n: Length of str2 [second string]510
std;
3std;
4
m: Length of str1 [first string] n: Length of str2 [second string]72
min[
7 m: Length of str1 [first string] n: Length of str2 [second string]74
m: Length of str1 [first string] n: Length of str2 [second string]786
#include
2
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]79
m: Length of str1 [first string] n: Length of str2 [second string]378
int
1#include
3
m: Length of str1 [first string] n: Length of str2 [second string]83
m: Length of str1 [first string] n: Length of str2 [second string]382
int
1#include
3
m: Length of str1 [first string] n: Length of str2 [second string]385
std;
4
std;
4
JavaScript
namespace
90
using
74
m: Length of str1 [first string] n: Length of str2 [second string]705
#include
2
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]805
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]807
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]809
int
90 m: Length of str1 [first string] n: Length of str2 [second string]811
#include
3std;
78
m: Length of str1 [first string] n: Length of str2 [second string]814
#include
3#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]818
int
90 m: Length of str1 [first string] n: Length of str2 [second string]820
#include
6std;
78
m: Length of str1 [first string] n: Length of str2 [second string]823
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]825
#include
3std;
4
#include
3std;
78
m: Length of str1 [first string] n: Length of str2 [second string]830
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]331
#include
3std;
78
m: Length of str1 [first string] n: Length of str2 [second string]835
#include
3#include
2
#include
6std;
78
m: Length of str1 [first string] n: Length of str2 [second string]840
#include
6#include
2
x,
1#include
4 std;
95
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 m: Length of str1 [first string] n: Length of str2 [second string]756
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
2std;
90
m: Length of str1 [first string] n: Length of str2 [second string]352
x,
1std;
4
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
2std;
90
m: Length of str1 [first string] n: Length of str2 [second string]860
min[
59
m: Length of str1 [first string] n: Length of str2 [second string]862
m: Length of str1 [first string] n: Length of str2 [second string]362
m: Length of str1 [first string] n: Length of str2 [second string]363
x,
1std;
4
#include
6std;
4
#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]872
m: Length of str1 [first string] n: Length of str2 [second string]873
std;
3std;
4
std;
43
m: Length of str1 [first string] n: Length of str2 [second string]378
int
1std;
46
m: Length of str1 [first string] n: Length of str2 [second string]382
int
1m: Length of str1 [first string] n: Length of str2 [second string]385
std;
52
m: Length of str1 [first string]
n: Length of str2 [second string]
72 min[
7 m: Length of str1 [first string]
n: Length of str2 [second string]
74 m: Length of str1 [first string]
n: Length of str2 [second string]
786 O[m x n]
Auxiliary
Space: O[ m ]
JavaScript
C++14
#include
namespace
90
using
74
m: Length of str1 [first string] n: Length of str2 [second string]705
namespace
4
m: Length of str1 [first string] n: Length of str2 [second string]895
int
m: Length of str1 [first string] n: Length of str2 [second string]897
#include
2
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]809
int
90 m: Length of str1 [first string] n: Length of str2 [second string]811
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]818
int
90 m: Length of str1 [first string] n: Length of str2 [second string]820
#include
3std;
78
m: Length of str1 [first string] n: Length of str2 [second string]830
#include
3std;
78
m: Length of str1 [first string] n: Length of str2 [second string]835
#include
6std;
78
m: Length of str1 [first string] n: Length of str2 [second string]840
std;
90
m: Length of str1 [first string] n: Length of str2 [second string]346
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
4 m: Length of str1 [first string] n: Length of str2 [second string]851
Độ phức tạp về thời gian: O [m x n] & nbsp; không gian phụ trợ: O [m]
#include
3std;
4
Đây là phiên bản ghi nhớ của đệ quy, tức là DP từ trên xuống:
using
namespace
std;
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]932
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]934
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]936
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]939
#include
3std;
4
std;
4
int
std;
6
#include
2
#include
3std;
9
m: Length of str1 [first string] n: Length of str2 [second string]948
int
1#include
3int
3
m: Length of str1 [first string] n: Length of str2 [second string]952
int
1#include
3int
m: Length of str1 [first string] n: Length of str2 [second string]956
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]895
int
m: Length of str1 [first string] n: Length of str2 [second string]960
int
m: Length of str1 [first string] n: Length of str2 [second string]962
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]964
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
min[
2std;
4
Java
m: Length of str1 [first string] n: Length of str2 [second string]390
m: Length of str1 [first string] n: Length of str2 [second string]391
min[
4 #include
75
#include
3min[
7 int
m: Length of str1 [first string] n: Length of str2 [second string]976
int
m: Length of str1 [first string] n: Length of str2 [second string]891
int
m: Length of str1 [first string] n: Length of str2 [second string]12
using
80int
m: Length of str1 [first string] n: Length of str2 [second string]983
#include
3#include
2
#include
6#include
4
m: Length of str1 [first string] n: Length of str2 [second string]28
m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]22
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
using
4#include
6#include
4
m: Length of str1 [first string] n: Length of str2 [second string]20
m: Length of str1 [first string] n: Length of str2 [second string]21
m: Length of str1 [first string] n: Length of str2 [second string]22
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
8#include
6#include
4 #include
004namespace
3
m: Length of str1 [first string] n: Length of str2 [second string]22
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]916
#include
6#include
4 #include
012namespace
3#include
014namespace
3
m: Length of str1 [first string] n: Length of str2 [second string]460
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
019namespace
3#include
021namespace
3#include
023#include
6std;
4
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
2x,
1int
m: Length of str1 [first string] n: Length of str2 [second string]930
x,
1#include
033namespace
3#include
023
x,
1#include
037namespace
3#include
039
x,
1#include
041namespace
3#include
021namespace
3#include
023
x,
1
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
048std;
90namespace
67namespace
3 #include
052
#include
6std;
4
#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]72
min[
7 m: Length of str1 [first string] n: Length of str2 [second string]74
m: Length of str1 [first string] n: Length of str2 [second string]516
#include
3#include
2
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]79
m: Length of str1 [first string] n: Length of str2 [second string]948
int
1#include
6
m: Length of str1 [first string] n: Length of str2 [second string]83
m: Length of str1 [first string] n: Length of str2 [second string]952
int
1#include
6int
m: Length of str1 [first string] n: Length of str2 [second string]956
#include
6int
#include
0777 ____690 int
#include
080namespace
3__
#include
6std;
78 using
88int
min[
01
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
091namespace
3#include
093x,
1#include
095namespace
3std;
3
#include
6#include
099
#include
3std;
4
std;
4
Python3
m: Length of str1 [first string] n: Length of str2 [second string]93
#include
104#include
105#include
4int
05
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
111#include
1122 #include
114
#include
105#include
4int
13
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]98
m: Length of str1 [first string] n: Length of str2 [second string]21
#include
111#include
1122 #include
04
#include
105#include
4#include
127
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
18namespace
3#include
131#include
112
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]916
#include
105#include
4#include
137#include
18 namespace
3#include
20__
#include
3#include
4#include
149#include
18
#include
6#include
162
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
164#include
18 namespace
3__#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
173#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
01#include
6#include
162
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
180__218#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
048#include
105
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
192Các
#include
1122____2204
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
180__218 namespace
3#include
209#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
01#include
6#include
162
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
180__218#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
048#include
105
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
192#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
01#include
6#include
162
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
180__218#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
048#include
105
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
192#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
01#include
6#include
162
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
180__218#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
048#include
105
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
192Các
#include
1122____2204
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
180__218 namespace
3#include
209#include
1122#include
204
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
164#include
18 namespace
3#include
219#include
3#include
4#include
2222218 namespace
3#include
225
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
18__#include
1122#include
231
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
233#include
18 namespace
3#include
2236#include
66#include
331
C#
#include
1122#include
231
m: Length of str1 [first string] n: Length of str2 [second string]98
#include
243#include
18 namespace
3#include
246#include
3#include
4#include
149#include
18
min[
4 #include
75
#include
105min[
7 int
#include
341#include
342 #include
343#include
342
int
08int
#include
350int
#include
352
#include
105#include
2
#include
3#include
4#include
357
#include
1122____14 using
4
#include
3#include
4#include
363
#include
1122 #include
8
#include
3#include
4#include
369
#include
112
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]916
#include
3#include
4#include
375
#include
3#include
377
#include
112#include
4#include
380
#include
112#include
382
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
385#include
112#include
387
#include
112
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
6
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
392#include
3std;
4
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
3#include
377
#include
112int
#include
401
#include
112#include
4#include
404
#include
1122402406
#include
6#include
408
#include
112#include
410
#include
112
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
112#include
414
#include
6#include
416
#include
112#include
418
#include
112#include
4#include
421
#include
112#include
423
#include
6#include
425
#include
112#include
418
#include
112
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
112#include
406
#include
6#include
433
#include
112#include
435
#include
112#include
4#include
438
#include
112#include
406
#include
6#include
442
#include
112#include
444
#include
112
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
112#include
414
#include
6#include
450
#include
112#include
452
#include
112
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
455#include
3std;
4
#include
105std;
4
#include
105min[
7
m: Length of str1 [first string] n: Length of str2 [second string]74
using
55#include
105#include
2
#include
3#include
342 #include
468
m: Length of str1 [first string] n: Length of str2 [second string]948
int
1#include
3#include
342 #include
473
m: Length of str1 [first string] n: Length of str2 [second string]952
int
1#include
3int
#include
478
Các
#include
3std;
78using
88int
#include
491
#include
3#include
2
Các
‘
#include
112#include
2
#include
6#include
508
#include
112std;
4
#include
3std;
4
#include
3#include
514
#include
105std;
4
std;
4
JavaScript
namespace
90
using
74 #include
520
#include
2
#include
105#include
4#include
357
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
using
4#include
105#include
4#include
530
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
8#include
105#include
4#include
536
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
m: Length of str1 [first string] n: Length of str2 [second string]916
#include
105#include
4#include
375
#include
105#include
544
#include
3#include
4#include
380
#include
3#include
549
#include
112
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
552#include
3#include
554
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
112
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
559#include
105std;
4
#include
105
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
105#include
544
#include
3#include
567
#include
3#include
4#include
570
#include
3#include
414
#include
112#include
574
#include
3#include
576
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]065
#include
112#include
582
#include
3#include
410
#include
3#include
4#include
421
#include
3#include
382
#include
112#include
591
#include
3#include
410
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
3#include
414
#include
112#include
599
#include
3#include
601
#include
3#include
4#include
438
#include
3#include
414
#include
112#include
608
#include
3#include
610
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]01
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]065
#include
112#include
616
#include
3#include
618
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]4
#include
621#include
105std;
4
std;
4
std;
43
m: Length of str1 [first string] n: Length of str2 [second string]948
int
1std;
46
m: Length of str1 [first string] n: Length of str2 [second string]952
int
1#include
631
m: Length of str1 [first string] n: Length of str2 [second string]227
int
90 #include
634std;
78#include
636
#include
2
#include
3
m: Length of str1 [first string] n: Length of str2 [second string]236
int
90 #include
641#include
3std;
78#include
644
#include
6#include
646
std;
4
#include
648
std;
52
Độ phức tạp về thời gian: O [m x n] & nbsp; không gian phụ trợ: o [m *n]+o [m+n] & nbsp; O[m x n]
Auxiliary Space: O[ m *n]+O[m+n]
.
Ứng dụng: Có nhiều ứng dụng thực tế của thuật toán chỉnh sửa khoảng cách, hãy giới thiệu API Lucene cho mẫu. Một ví dụ khác, hiển thị tất cả các từ trong một từ điển gần gần với một từ được đánh vần là từ ngữ nhất định.: There are many practical applications of edit distance algorithm, refer Lucene API for sample. Another example, display all the words in a dictionary that are near proximity to a given wordincorrectly spelled word.
Cảm ơn Vivek Kumar vì đã đề xuất các bản cập nhật. Cảm ơn đến Venki đã cung cấp bài đăng ban đầu. Vui lòng viết nhận xét nếu bạn tìm thấy bất cứ điều gì không chính xác hoặc bạn muốn chia sẻ thêm thông tin về chủ đề được thảo luận ở trên & NBSP;
Thanks to Venki for providing initial post. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above