Skip to content

Commit af247b5

Browse files
committed
chore(translate): add Vietnamese
1 parent 0b1bd47 commit af247b5

File tree

38 files changed

+1798
-697
lines changed

38 files changed

+1798
-697
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1+
# Hamming Distance
2+
13
_Read this in other languages:_
24
[_Tiếng Việt_](README.md)
5+
6+
the Hamming distance between two strings of equal length is the
7+
number of positions at which the corresponding symbols are
8+
different. In other words, it measures the minimum number of
9+
substitutions required to change one string into the other, or
10+
the minimum number of errors that could have transformed one
11+
string into the other. In a more general context, the Hamming
12+
distance is one of several string metrics for measuring the
13+
edit distance between two sequences.
14+
15+
## Examples
16+
17+
The Hamming distance between:
18+
19+
- "ka**rol**in" and "ka**thr**in" is **3**.
20+
- "k**a**r**ol**in" and "k**e**r**st**in" is **3**.
21+
- 10**1**1**1**01 and 10**0**1**0**01 is **2**.
22+
- 2**17**3**8**96 and 2**23**3**7**96 is **3**.
23+
24+
## References
25+
26+
[Wikipedia](https://en.wikipedia.org/wiki/Hamming_distance)
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
# Hamming Distance
1+
# Khoảng cách Hamming
22

3-
the Hamming distance between two strings of equal length is the
4-
number of positions at which the corresponding symbols are
5-
different. In other words, it measures the minimum number of
6-
substitutions required to change one string into the other, or
7-
the minimum number of errors that could have transformed one
8-
string into the other. In a more general context, the Hamming
9-
distance is one of several string metrics for measuring the
10-
edit distance between two sequences.
3+
_Nhấn vào đây để đọc bằng ngôn ngữ khác:_
4+
[_English_](README.en-EN.md)
115

12-
## Examples
6+
Khoảng cách Hamming giữa hai chuỗi có cùng độ dài là số lượng vị trí mà các ký tự tương ứng khác nhau. Nó đo lường số lượng thay thế tối thiểu cần thiết để biến đổi một chuỗi thành chuỗi khác, hoặc số lượng lỗi tối thiểu có thể đã biến đổi một chuỗi thành chuỗi khác. Trong ngữ cảnh tổng quát hơn, khoảng cách Hamming là một trong các phương pháp đo lường khoảng cách chỉnh sửa giữa hai chuỗi.
137

14-
The Hamming distance between:
8+
## Ví dụ
159

16-
- "ka**rol**in" and "ka**thr**in" is **3**.
17-
- "k**a**r**ol**in" and "k**e**r**st**in" is **3**.
18-
- 10**1**1**1**01 and 10**0**1**0**01 is **2**.
19-
- 2**17**3**8**96 and 2**23**3**7**96 is **3**.
10+
Khoảng cách Hamming giữa:
2011

21-
## References
12+
- "ka**rol**in" và "ka**thr**in" là **3**.
13+
- "k**a**r**ol**in" và "k**e**r**st**in" là **3**.
14+
- 10**1**1**1**01 và 10**0**1**0**01 là **2**.
15+
- 2**17**3**8**96 và 2**23**3**7**96 là **3**.
16+
17+
## Tham khảo
2218

2319
[Wikipedia](https://en.wikipedia.org/wiki/Hamming_distance)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1+
# Knuth–Morris–Pratt Algorithm
2+
13
_Read this in other languages:_
24
[_Tiếng Việt_](README.md)
5+
6+
The Knuth–Morris–Pratt string searching algorithm (or
7+
KMP algorithm) searches for occurrences of a "word" `W`
8+
within a main "text string" `T` by employing the
9+
observation that when a mismatch occurs, the word itself
10+
embodies sufficient information to determine where the
11+
next match could begin, thus bypassing re-examination
12+
of previously matched characters.
13+
14+
## Complexity
15+
16+
-**Time:**`O(|W| + |T|)` (much faster comparing to trivial `O(|W| * |T|)`)
17+
-**Space:**`O(|W|)`
18+
19+
## References
20+
21+
-[Wikipedia](https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm)
22+
-[YouTube](https://www.youtube.com/watch?v=GTJr8OvyEVQ&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
# Knuth–Morris–Pratt Algorithm
1+
# Thuật toán Knuth–Morris–Pratt
22

3-
The Knuth–Morris–Pratt string searching algorithm (or
4-
KMP algorithm) searches for occurrences of a "word" `W`
5-
within a main "text string" `T` by employing the
6-
observation that when a mismatch occurs, the word itself
7-
embodies sufficient information to determine where the
8-
next match could begin, thus bypassing re-examination
9-
of previously matched characters.
3+
_Nhấn vào đây để đọc bằng ngôn ngữ khác:_
4+
[_English_](README.en-EN.md)
105

11-
## Complexity
6+
Thuật toán tìm kiếm chuỗi Knuth–Morris–Pratt (hoặc thuật toán KMP) tìm kiếm các lần xuất hiện của một "từ" `W` trong một "chuỗi văn bản chính" `T` bằng cách sử dụng quan sát rằng khi một không khớp xảy ra, từ chính nó cung cấp đủ thông tin để xác định nơi mà sự khớp tiếp theo có thể bắt đầu, qua đó bỏ qua việc kiểm tra lại các ký tự đã khớp trước đó.
127

13-
-**Time:**`O(|W| + |T|)` (much faster comparing to trivial `O(|W| * |T|)`)
14-
-**Space:**`O(|W|)`
8+
## Độ phức tạp
159

16-
## References
10+
-**Thời gian:**`O(|W| + |T|)` (nhanh hơn nhiều so với phương pháp trực tiếp `O(|W| * |T|)`)
11+
-**Không gian:**`O(|W|)`
12+
13+
## Tham khảo
1714

1815
-[Wikipedia](https://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm)
1916
-[YouTube](https://www.youtube.com/watch?v=GTJr8OvyEVQ&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,118 @@
1+
# Levenshtein Distance
2+
13
_Read this in other languages:_
24
[_Tiếng Việt_](README.md)
5+
6+
The Levenshtein distance is a string metric for measuring the
7+
difference between two sequences. Informally, the Levenshtein
8+
distance between two words is the minimum number of
9+
single-character edits (insertions, deletions or substitutions)
10+
required to change one word into the other.
11+
12+
## Definition
13+
14+
Mathematically, the Levenshtein distance between two strings
15+
`a` and `b` (of length `|a|` and `|b|` respectively) is given by
16+
![Levenshtein](https://wikimedia.org/api/rest_v1/media/math/render/svg/4cf357d8f2135035207088d2c7b890fb4b64e410)
17+
where
18+
19+
![Levenshtein](https://wikimedia.org/api/rest_v1/media/math/render/svg/f0a48ecfc9852c042382fdc33c19e11a16948e85)
20+
21+
where
22+
![Levenshtein](https://wikimedia.org/api/rest_v1/media/math/render/svg/52512ede08444b13838c570ba4a3fc71d54dbce9)
23+
is the indicator function equal to `0` when
24+
![Levenshtein](https://wikimedia.org/api/rest_v1/media/math/render/svg/231fda9ee578f0328c5ca28088d01928bb0aaaec)
25+
and equal to 1 otherwise, and
26+
![Levenshtein](https://wikimedia.org/api/rest_v1/media/math/render/svg/bdc0315678caad28648aafedb6ebafb16bd1655c)
27+
is the distance between the first `i` characters of `a` and the first
28+
`j` characters of `b`.
29+
30+
Note that the first element in the minimum corresponds to
31+
deletion (from `a` to `b`), the second to insertion and
32+
the third to match or mismatch, depending on whether the
33+
respective symbols are the same.
34+
35+
## Example
36+
37+
For example, the Levenshtein distance between `kitten` and
38+
`sitting` is `3`, since the following three edits change one
39+
into the other, and there is no way to do it with fewer than
40+
three edits:
41+
42+
1.**k**itten → **s**itten (substitution of "s" for "k")
43+
2. sitt**e**n → sitt**i**n (substitution of "i" for "e")
44+
3. sittin → sittin**g** (insertion of "g" at the end).
45+
46+
## Applications
47+
48+
This has a wide range of applications, for instance, spell checkers, correction
49+
systems for optical character recognition, fuzzy string searching, and software
50+
to assist natural language translation based on translation memory.
51+
52+
## Dynamic Programming Approach Explanation
53+
54+
Let’s take a simple example of finding minimum edit distance between
55+
strings `ME` and `MY`. Intuitively you already know that minimum edit distance
56+
here is `1` operation, which is replacing `E` with `Y`. But
57+
let’s try to formalize it in a form of the algorithm in order to be able to
58+
do more complex examples like transforming `Saturday` into `Sunday`.
59+
60+
To apply the mathematical formula mentioned above to `ME → MY` transformation
61+
we need to know minimum edit distances of `ME → M`, `M → MY` and `M → M` transformations
62+
in prior. Then we will need to pick the minimum one and add _one_ operation to
63+
transform last letters `E → Y`. So minimum edit distance of `ME → MY` transformation
64+
is being calculated based on three previously possible transformations.
65+
66+
To explain this further let’s draw the following matrix:
67+
68+
![Levenshtein Matrix](https://cdn-images-1.medium.com/max/1600/1*aTunSUoy0BJyYBVn4tWGrA.png)
69+
70+
- Cell `(0:1)` contains red number 1. It means that we need 1 operation to
71+
transform `M` to an empty string. And it is by deleting `M`. This is why this number is red.
72+
- Cell `(0:2)` contains red number 2. It means that we need 2 operations
73+
to transform `ME` to an empty string. And it is by deleting `E` and `M`.
74+
- Cell `(1:0)` contains green number 1. It means that we need 1 operation
75+
to transform an empty string to `M`. And it is by inserting `M`. This is why this number is green.
76+
- Cell `(2:0)` contains green number 2. It means that we need 2 operations
77+
to transform an empty string to `MY`. And it is by inserting `Y` and `M`.
78+
- Cell `(1:1)` contains number 0. It means that it costs nothing
79+
to transform `M` into `M`.
80+
- Cell `(1:2)` contains red number 1. It means that we need 1 operation
81+
to transform `ME` to `M`. And it is by deleting `E`.
82+
- And so on...
83+
84+
This looks easy for such small matrix as ours (it is only `3x3`). But here you
85+
may find basic concepts that may be applied to calculate all those numbers for
86+
bigger matrices (let’s say a `9x7` matrix for `Saturday → Sunday` transformation).
87+
88+
According to the formula you only need three adjacent cells `(i-1:j)`, `(i-1:j-1)`, and `(i:j-1)` to
89+
calculate the number for current cell `(i:j)`. All we need to do is to find the
90+
minimum of those three cells and then add `1` in case if we have different
91+
letters in `i`'s row and `j`'s column.
92+
93+
You may clearly see the recursive nature of the problem.
94+
95+
![Levenshtein Matrix](https://cdn-images-1.medium.com/max/1600/1*w8UB4DSvBnAK6mBXRGQDjw.png)
96+
97+
Let's draw a decision graph for this problem.
98+
99+
![Minimum Edit Distance Decision Graph](https://cdn-images-1.medium.com/max/1600/1*8jD0qvr5B9PwRFM_9z7q9A.png)
100+
101+
You may see a number of overlapping sub-problems on the picture that are marked
102+
with red. Also there is no way to reduce the number of operations and make it
103+
less than a minimum of those three adjacent cells from the formula.
104+
105+
Also you may notice that each cell number in the matrix is being calculated
106+
based on previous ones. Thus the tabulation technique (filling the cache in
107+
bottom-up direction) is being applied here.
108+
109+
Applying this principle further we may solve more complicated cases like
110+
with `Saturday → Sunday` transformation.
111+
112+
![Levenshtein distance](https://cdn-images-1.medium.com/max/2600/1*497gMaFErzJpCXG7kS_7dw.png)
113+
114+
## References
115+
116+
-[Wikipedia](https://en.wikipedia.org/wiki/Levenshtein_distance)
117+
-[YouTube](https://www.youtube.com/watch?v=We3YDTzNXEk&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8)
118+
-[ITNext](https://itnext.io/dynamic-programming-vs-divide-and-conquer-2fea680becbe)

0 commit comments

Comments
(0)