Skip to content

Commit

Permalink
【动态规划之正则表达式】标注翻译者 PaperJets 及链接
Browse files Browse the repository at this point in the history
  • Loading branch information
labuladong committed Feb 29, 2020
1 parent 4ce89ae commit 7078491
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

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

**Author: [labuladong](https://github.com/labuladong)**

**Translator: [YourName](https://github.com/YourName)**

**Author: [labuladong](https://github.com/labuladong)**

你的链接可以指向任何你希望的地方。

### 翻译约定
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Implement Queue using Stacks |Implement Stack using Queues

**Author**:[labuladong](https://github.com/labuladong)

**Translator**:[walsvid](https://github.com/walsvid)

**Author**:[labuladong](https://github.com/labuladong)

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:

![](../pictures/stackqueue/1.jpg)
Expand Down
4 changes: 2 additions & 2 deletions data_structure/reverse_part_of_a_linked_list_via_recursion.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Reverse Part of a Linked List via Recusion

**Author: [labuladong](https://github.com/labuladong)**

**Translator: [CarrieOn](https://github.com/CarrieOn)**

**Author: [labuladong](https://github.com/labuladong)**

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**?

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.
Expand Down
12 changes: 7 additions & 5 deletions dynamic_programming/RegularExpression.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Regular Expression - Dynamic Programming

**Translator: [PaperJets](https://github.com/PaperJets)**

**Author: [labuladong](https://github.com/labuladong)**

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".

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.
Expand Down Expand Up @@ -128,7 +132,7 @@ if len(pattern) >= 2 and pattern[1] == '*':
```
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:

![example](../pictures/%E6%AD%A3%E5%88%99/regex_example.jpg)
![example](../pictures/regularExpression/regex_example.jpg)

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

Expand Down Expand Up @@ -171,8 +175,7 @@ def isMatch(text, pattern) -> bool:
else:
return first and isMatch(text[1:], pattern[1:])
```
**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!**
**有的读者也许会问,你怎么知道这个问题是个动态规划问题呢,你怎么知道它就存在「重叠子问题」呢,这似乎不容易看出来呀?**
**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!**


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.
Expand All @@ -185,8 +188,7 @@ def fib(n):
fib(n - 2) #2
```

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.**
**只要你发现一条重复路径,这样的重复路径一定存在千万条,意味着巨量子问题重叠。**
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.**

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

Expand Down
Binary file removed pictures/regularExpression/example.png
Binary file not shown.
Binary file removed pictures/regularExpression/title.png
Binary file not shown.

0 comments on commit 7078491

Please sign in to comment.