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

Skip to content

Commit a10d65b

Browse files
committed
Moved A* algorithm close to Dijkstra's algorithm.
1 parent 1143090 commit a10d65b

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ You can skip the more difficult problems and do them later.
115115
- [1584. Min Cost to Connect All Points](en/1001-2000/1584-min-cost-to-connect-all-points.md) was solved in _Python, Java, C++, JavaScript, C#, Go, Ruby_ and 2 ways.
116116
- [207. Course Schedule](en/1-1000/207-course-schedule.md) was solved in _Python, Java, C++, C#_ and 2 ways.
117117
- [1514. Path with Maximum Probability](en/1001-2000/1514-path-with-maximum-probability.md) was solved in _Python_ and 2 ways.
118+
- [752. Open the Lock](en/1-1000/752-open-the-lock.md) was solved in _Python_ and 2 ways.
118119
- [743. Network Delay Time](en/1-1000/743-network-delay-time.md) was solved in _Python_ and 2 ways.
119120
- [787. Cheapest Flights Within K Stops](en/1-1000/787-cheapest-flights-within-k-stops.md) was solved in _Python_.
120121
- [1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance](en/1001-2000/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.md) was solved in _Python_.
121-
- [752. Open the Lock](en/1-1000/752-open-the-lock.md) was solved in _Python_ and 2 ways.
122122

123123
# Others
124124
- [433. Minimum Genetic Mutation](en/1-1000/433-minimum-genetic-mutation.md) was solved in _Python_ and 2 ways.

en/1-1000/743-network-delay-time.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ For a detailed description of **Dijkstra's algorithm**, please refer to [1514. P
5656
### Common graph theory algorithm comparison table
5757
|Algorithm name|Main application scenarios|Optimization methods|Importance|Difficulty|min_<br>distances|Negative weights|Additional application scenarios|
5858
|--------------|--------------------------|--------------------|----------|----------|-------------|----------------|--------------------------------|
59-
|[Prim's algorithm](../1001-2000/1584-min-cost-to-connect-all-points.md) |Minimum Spanning Tree |Heap Sort Simplify|Important |Medium |Used |Can handle||
60-
|[Kruskal's algorithm](../1001-2000/1584-min-cost-to-connect-all-points-2.md) |Minimum Spanning Tree |No need |important |Relatively hard|Not used|Can handle|Relative: [Undirected Graph Cycle Detection](./684-redundant-connection.md), [Directed Graph Cycle Detection](./685-redundant-connection-ii.md)|
61-
|[Dijkstra's algorithm](../1001-2000/1514-path-with-maximum-probability.md) |Single-Source Shortest Path |Heap Sort |Very important|Relatively hard|Used |Cannot handle||
62-
|[Bellman-Ford algorithm](./743-network-delay-time.md) |Single-Source Shortest Path |Queue-Improved |Very Important|Easy |Used |Can handle|[Detect Negative Cycles](https://www.geeksforgeeks.org/detect-negative-cycle-graph-bellman-ford/), <br>[Shortest Hop-Bounded Paths](./787-cheapest-flights-within-k-stops.md)|
63-
|[Floyd–Warshall](../1001-2000/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.md)|Multi-Source Shortest Path |No need |Less important|Relatively hard|Used |Can handle||
59+
|[Prim's algorithm](../1001-2000/1584-min-cost-to-connect-all-points.md) |Minimum Spanning Tree |Heap Sort Simplify|Important |Medium |Used |Can handle||
60+
|[Kruskal's algorithm](../1001-2000/1584-min-cost-to-connect-all-points-2.md) |Minimum Spanning Tree |No need |important |Relatively hard|Not used|Can handle|Relative: [Undirected Graph Cycle Detection](./684-redundant-connection.md), [Directed Graph Cycle Detection](./685-redundant-connection-ii.md)|
61+
|[Dijkstra's algorithm](../1001-2000/1514-path-with-maximum-probability.md) |Single-Source Shortest Path|Heap Sort |Very important|Relatively hard|Used |Cannot handle||
62+
|[A* search algorithm](./752-open-the-lock.md) |Single-Source Shortest Path|Built-in Heap Sort|Very important|Medium |Not used|It depends||
63+
|[Bellman-Ford algorithm](./743-network-delay-time.md) |Single-Source Shortest Path|Queue-Improved |Very Important|Easy |Used |Can handle|[Detect Negative Cycles](https://www.geeksforgeeks.org/detect-negative-cycle-graph-bellman-ford/), <br>[Shortest Hop-Bounded Paths](./787-cheapest-flights-within-k-stops.md)|
64+
|[Floyd–Warshall](../1001-2000/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.md)|Multi-Source Shortest Path |No need |Less important|Relatively hard|Used |Can handle||
6465

6566
## Complexity
6667
**V**: vertex count, **E**: Edge count.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ We can think of this problem as a shortest path problem on a graph: there are `1
6969

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

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!
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

7474
_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.
7575

zh/1-1000/743-network-delay-time.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@
5858

5959
|算法名称|主要的适用场景|优化方式|重要度|难度|min_<br>distances|负边权值|额外的适用场景|
6060
|-------|-----------|-------|-------|---|-------------|--------|------------|
61-
|[Prim算法](../1001-2000/1584-min-cost-to-connect-all-points.md) |最小生成树 |堆排序简化|重要 |中等|用到|能处理||
62-
|[Kruskal算法](../1001-2000/1584-min-cost-to-connect-all-points-2.md) |最小生成树 |无需优化 |重要 |较难|不用|能处理|相关:[无向图环检测](./684-redundant-connection.md), [有向图环检测](./685-redundant-connection-ii.md)|
63-
|[Dijkstra算法](../1001-2000/1514-path-with-maximum-probability.md) |单源最短路径|堆排序优化 |很重要 |较难|用到|无能力||
64-
|[Bellman-Ford](./743-network-delay-time.md) |单源最短路径|集合优化 |很重要 |简单|用到|能处理|[负环检测](https://www.geeksforgeeks.org/detect-negative-cycle-graph-bellman-ford/), [限定步数最短路径](./787-cheapest-flights-within-k-stops.md)|
61+
|[Prim算法](../1001-2000/1584-min-cost-to-connect-all-points.md) |最小生成树 |堆排序简化|重要 |中等|用到|能处理||
62+
|[Kruskal算法](../1001-2000/1584-min-cost-to-connect-all-points-2.md) |最小生成树 |无需优化 |重要 |较难|不用|能处理|相关:[无向图环检测](./684-redundant-connection.md), [有向图环检测](./685-redundant-connection-ii.md)|
63+
|[Dijkstra算法](../1001-2000/1514-path-with-maximum-probability.md) |单源最短路径|堆排序优化|很重要 |较难|用到|无能力||
64+
|[A* 算法](./752-open-the-lock.md) |单源最短路径|固有堆排序|很重要 |中等|不用|看情况||
65+
|[Bellman-Ford](./743-network-delay-time.md) |单源最短路径|集合优化 |很重要 |简单|用到|能处理|[负环检测](https://www.geeksforgeeks.org/detect-negative-cycle-graph-bellman-ford/), [限定步数最短路径](./787-cheapest-flights-within-k-stops.md)|
6566
|[Floyd–Warshall](../1001-2000/1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.md)|多源最短路径|无需优化 |较不重要|较难|用到|能处理||
6667

6768
## 复杂度

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272

7373
`A* (A-Star) 算法` 会对每一个`顶点``目标顶点`**距离**进行计算,**距离近的顶点优先处理**,相当于为下一步处理哪个顶点指明了方向,因此性能有很大的提升!
7474

75+
`A* (A-Star) 算法``Dijkstra's 算法` 比较像,但`A* 算法``目标顶点`是明确的,但`Dijkstra's 算法`不明确。`Dijkstra's 算法`是走到哪个顶点就计算从`起点``那个顶点`的距离。
76+
7577
#### A* (A-Star) 算法的两(三)个关键动作
7678
1. 要用 `priority_queue`
7779
2. 计算距离的`启发式函数`**精心设计**。设计不好,将导致不易察觉的结果错误!

0 commit comments

Comments
 (0)