Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1143090

Browse files
committed
752-open-the-lock.md Reworded.
1 parent bb350be commit 1143090

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

en/1-1000/752-open-the-lock.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ We can think of this problem as a shortest path problem on a graph: there are `1
6363

6464
* `Breadth-First Search` emphasizes first-in-first-out, so a **queue** is needed.
6565

66-
### Solution 2: A* (A-Star) Algorithm
66+
### Solution 2: A* (A-Star) Search Algorithm
6767

6868
**A-Star Algorithm** can be used to improve the performance of **Breadth-First Search Algorithm**.
6969

7070
**Breadth-First Search** treats each vertex equally, which inevitably leads to poor performance.
7171

72-
The `A* (A-Star) algorithm` calculates the **distance** between each `vertex` and the `target vertex`, and **prioritizes vertices with closer distances**, which is equivalent to indicating which vertex to process next, so the performance is greatly improved!
72+
The `A* (A-star) search algorithm` calculates the **distance** between each `vertex` and the `target vertex`, and **prioritizes vertices with closer distances**, which is equivalent to indicating which vertex to process next, so the performance is greatly improved!
7373

74-
#### A* (A-Star) Algorithm Has Two (or Three) Key Actions
74+
_A* (A-star) search algorithm_ is similar to _Dijkstra's algorithm_, but the `target vertex` of _A* (A-star) search algorithm_ is clear, while that of _Dijkstra's algorithm_ is not. _Dijkstra's algorithm_ calculates the `distance` from the `starting vertex` to the `vertex` it reaches.
75+
76+
#### A* (A-Star) Search Algorithm Has Two (or Three) Key Actions
7577
1. Use `priority_queue`.
76-
2. The function for calculating `distance` should be **carefully designed** (poor design will lead to **subtle** errors in the results).
78+
2. The **heuristic function** for calculating `distance` should be **carefully designed** (poor design will lead to **subtle** errors in the results).
7779
3. In special cases, simply using `distance` as the sorting basis of `priority_queue` is not enough, and it is also necessary to **adjust** (for example, add it to the `number of steps` variable value) to make the last few steps accurate (not involved in this example, yet in this one [1197. Minimum Knight Moves](https://leetcode.com/problems/minimum-knight-moves/)).
7880

7981
## Complexity
@@ -83,7 +85,7 @@ The `A* (A-Star) algorithm` calculates the **distance** between each `vertex` an
8385
* Time: `O(10^4)`.
8486
* Space: `O(N)`.
8587

86-
### Solution 2: A* (A-Star) Algorithm
88+
### Solution 2: A* (A-Star) Search Algorithm
8789
* Time: `O(5 * 4 * 4 * 2 + N)`.
8890
* Space: `O(N)`.
8991

@@ -141,7 +143,7 @@ def closest_digits(digit):
141143
return (digit - 1, digit + 1)
142144
```
143145

144-
### Solution 2: A* (A-Star) Algorithm
146+
### Solution 2: A* (A-Star) Search Algorithm
145147
```python
146148
class Solution:
147149
def openLock(self, deadends: List[str], target_digits: str) -> int:

en/3001-4000/unorganized.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Add a table to show the differences between A-Start and breadth-first search
195195
- 1584-min-cost-to-connect-all-points-2.md
196196
- 1514-path-with-maximum-probability.md
197197
- 1334 https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
198+
- 752 a star
198199

199200
## other finished problems
200201
- https://leetcode.com/problems/k-closest-points-to-origin/

zh/1-1000/752-open-the-lock.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
#### A* (A-Star) 算法的两(三)个关键动作
7676
1. 要用 `priority_queue`
77-
2. 计算距离的函数要**精心设计**。设计不好,将导致不易察觉的结果错误!
77+
2. 计算距离的`启发式函数`**精心设计**。设计不好,将导致不易察觉的结果错误!
7878
3. 在特殊情况下,单纯地用`距离`作为`priority_queue`的排序依据还不够,还要**调整一下**(比如与`步数`变量值相加),以使最后几步能精确(本例子不涉及,但这个例子 [1197. Minimum Knight Moves](https://leetcode.com/problems/minimum-knight-moves/) 涉及)。
7979

8080
## 复杂度

0 commit comments

Comments
 (0)