Skip to content

Commit 7078491

Browse files
committed
【动态规划之正则表达式】标注翻译者 PaperJets 及链接
1 parent 4ce89ae commit 7078491

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
翻译完成后,你可以删除文末的公众号二维码。对于第一个提交的翻译版本,你可以在文章开头添加作者和翻译者:
66

7-
**Author: [labuladong](https://github.com/labuladong)**
8-
97
**Translator: [YourName](https://github.com/YourName)**
108

9+
**Author: [labuladong](https://github.com/labuladong)**
10+
1111
你的链接可以指向任何你希望的地方。
1212

1313
### 翻译约定

data_structure/ImplementQueueUsingStacksImplementStackUsingQueues.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Implement Queue using Stacks |Implement Stack using Queues
22

3-
**Author**:[labuladong](https://github.com/labuladong)
4-
53
**Translator**:[walsvid](https://github.com/walsvid)
64

5+
**Author**:[labuladong](https://github.com/labuladong)
6+
77
Queue is a FIFO (first-in-first-out) strategy data structure, while Stack is a FILO (first-in-last-out) data structure. The visual description of these data structures is shown in the figure:
88

99
![](../pictures/stackqueue/1.jpg)

data_structure/reverse_part_of_a_linked_list_via_recursion.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Reverse Part of a Linked List via Recusion
22

3-
**Author: [labuladong](https://github.com/labuladong)**
4-
53
**Translator: [CarrieOn](https://github.com/CarrieOn)**
64

5+
**Author: [labuladong](https://github.com/labuladong)**
6+
77
It's easy to reverse a single linked list using iteration, however it's kind of difficult to come up with a recursive solution. Furthermore, if only part of a linked list needs reversed, can you nail it with **recursion**?
88

99
If you haven't known how to **recursively reverse a single linked list**, no worry, we will start right here and guide you step by step to a deeper level.

dynamic_programming/RegularExpression.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Regular Expression - Dynamic Programming
22

3+
**Translator: [PaperJets](https://github.com/PaperJets)**
4+
5+
**Author: [labuladong](https://github.com/labuladong)**
6+
37
The previous article, "Dynamic Programming in Detail," was very well-received. Today, I'm going to talk about a practical application: Regular Expression. I highly recommend you to take a look at the previous article, if you don't know what is "Dynamic Programming".
48

59
Regular Expression is an ingenious algorithm but is a little bit hard to understand. This article mainly focuses on the implementation of two Regular Expression symbols: period「.」and asterisk「*」. Don't worry if you have never used Regular Expression; I will introduce it later. At the end of this article, I'll share with you a tip to quickly find the overlapping subproblems.
@@ -128,7 +132,7 @@ if len(pattern) >= 2 and pattern[1] == '*':
128132
```
129133
As we can see, we keep the 「\*」 in the pattern and pushed the text backwards to implement the function of 「*」 to match the characters repeatedly for many times. A simple example will illustrate the logic. Suppose 'pattern = a*', 'text = aaa', we can draw a picture to see the matching process:
130134

131-
![example](../pictures/%E6%AD%A3%E5%88%99/regex_example.jpg)
135+
![example](../pictures/regularExpression/regex_example.jpg)
132136

133137
At this point, the regular expression algorithm is almost complete.
134138

@@ -171,8 +175,7 @@ def isMatch(text, pattern) -> bool:
171175
else:
172176
return first and isMatch(text[1:], pattern[1:])
173177
```
174-
**Some readers may ask, how do you know that this problem is a dynamic programming problem, how do you know that there is an overlapping subproblem? It's not easy to find that!**
175-
**有的读者也许会问,你怎么知道这个问题是个动态规划问题呢,你怎么知道它就存在「重叠子问题」呢,这似乎不容易看出来呀?**
178+
**Some readers may ask, how do you know that this problem is a dynamic programming problem, how do you know that there is an overlapping subproblem? It's not easy to find that!**
176179

177180

178181
The clearest way is to answer this question is to assume an input and then draw a recursion tree. And you will definitely find the same node, which is a quantitative analysis. In fact, without so much trouble, let me teach you the qualitative analysis, at a glance can see the "overlapping sub-problem" property.
@@ -185,8 +188,7 @@ def fib(n):
185188
fib(n - 2) #2
186189
```
187190

188-
Look at the frame, how do I get from the original problem f(n) to the sub-problem f(n - 2)? There are two paths, one is f(n) -> #1 -> #1, and the other is f(n) -> #2. The former recurses twice; the latter recurse once. Two different computational paths but all face the same problem, which is called the "overlap subproblem". It is certain that **as long as you find a repeated path, there must be tens of thousands of such repeated paths, meaning that the huge quantum problem overlaps.**
189-
**只要你发现一条重复路径,这样的重复路径一定存在千万条,意味着巨量子问题重叠。**
191+
Look at the frame, how do I get from the original problem f(n) to the sub-problem f(n - 2)? There are two paths, one is f(n) -> #1 -> #1, and the other is f(n) -> #2. The former recurses twice; the latter recurse once. Two different computational paths but all face the same problem, which is called the "overlap subproblem". It is certain that **as long as you find a repeated path, there must be tens of thousands of such repeated paths, meaning that the huge quantum problem overlaps.**
190192

191193
Similarly, for this problem, we still abstract the algorithm framework first:
192194

-363 KB
Binary file not shown.

pictures/regularExpression/title.png

-163 KB
Binary file not shown.

0 commit comments

Comments
 (0)