You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/1-1000/752-open-the-lock.md
+8-6Lines changed: 8 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -63,17 +63,19 @@ We can think of this problem as a shortest path problem on a graph: there are `1
63
63
64
64
*`Breadth-First Search` emphasizes first-in-first-out, so a**queue** is needed.
65
65
66
-
###Solution 2: A* (A-Star) Algorithm
66
+
###Solution 2: A* (A-Star)SearchAlgorithm
67
67
68
68
**A-Star Algorithm** can be used to improve the performance of**Breadth-First Search Algorithm**.
69
69
70
70
**Breadth-First Search** treats each vertex equally, which inevitably leads to poor performance.
71
71
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!
73
73
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
75
77
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**heuristicfunction** for calculating`distance` should be**carefully designed** (poor design will lead to**subtle** errors in the results).
77
79
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/)).
78
80
79
81
##Complexity
@@ -83,7 +85,7 @@ The `A* (A-Star) algorithm` calculates the **distance** between each `vertex` an