forked from itcharge/LeetCode-Py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
113 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ents/08.Graph/04.Graph-Shortest-Path/01.Graph-Single-Source-Shortest-Path-01.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
## 1. 单源最短路径的定义 | ||
|
||
> **单源最短路径(Single Source Shortest Path)**:对于一个带权图 $G = (V, E)$,其中每条边的权重是一个实数。另外,给定 $v$ 中的一个顶点,称之为源点。则源点到其他所有各个顶点之间的最短路径长度,称为单源最短路径。 | ||
这里的路径长度,指的是路径上各边权之和。 | ||
|
||
单源最短路径问题的核心是找到从源点到其他各个顶点的路径,使得路径上边的权重之和最小。这个问题在许多实际应用中都非常重要,比如网络路由、地图导航、通信网络优化等。 | ||
|
||
常见的解决单源最短路径问题的算法包括: | ||
|
||
1. **Dijkstra 算法**:一种贪心算法,用于解决无负权边的情况。它逐步扩展当前已知最短路径的范围,选择当前距离起始节点最近的节点,并更新与该节点相邻的节点的距离。 | ||
2. **Bellman-Ford 算法**:适用于有负权边的情况。它通过多次迭代来逐步逼近最短路径,每次迭代都尝试通过更新边的权重来缩短路径。 | ||
3. **SPFA 算法**:优化的 Bellman-Ford 算法,它在每次迭代中不遍历所有的边,而是选择性地更新与当前节点相关的边,从而提高了算法的效率。 | ||
|
||
这些算法根据图的特点和问题的需求有所不同,选择适合的算法可以在不同情况下有效地解决单源最短路径问题。 | ||
|
||
## 2. Dijkstra 算法 | ||
|
||
### 2.1 Dijkstra 算法的算法思想 | ||
|
||
> **Dijkstra 算法的算法思想**:通过逐步选择距离起始节点最近的节点,并根据这些节点的路径更新其他节点的距离,从而逐步找到最短路径。 | ||
### 2.2 Dijkstra 算法的实现步骤 | ||
|
||
### 2.3 Dijkstra 算法的实现代码 | ||
|
||
```Python | ||
|
||
``` | ||
|
||
## 3. Bellman-Ford 算法 | ||
|
||
### 3.1 Bellman-Ford 算法的算法思想 | ||
|
||
### 3.2 Bellman-Ford 算法的实现步骤 | ||
|
||
### 3.3 Bellman-Ford 算法的实现代码 | ||
|
||
```Python | ||
|
||
``` | ||
|
||
## 4. SPFA 算法 | ||
|
||
### 4.1 SPFA 算法的算法思想 | ||
|
||
### 4.2 SPFA 算法的实现步骤 | ||
|
||
### 4.3 SPFA 算法的实现代码 | ||
|
||
```Python | ||
``` | ||
|
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
...ts/08.Graph/04.Graph-Shortest-Path/03.Graph-Single-Source-Shortest-Path-List.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### 单源最短路径题目 | ||
|
||
| 题号 | 标题 | 题解 | 标签 | 难度 | | ||
| :------ | :------ | :------ | :------ | :------ | | ||
| 0407 | [接雨水 II](https://leetcode.cn/problems/trapping-rain-water-ii/) | | 广度优先搜索、数组、矩阵、堆(优先队列) | 困难 | | ||
| 0743 | [网络延迟时间](https://leetcode.cn/problems/network-delay-time/) | | 深度优先搜索、广度优先搜索、图、最短路、堆(优先队列) | 中等 | | ||
| 0787 | [K 站中转内最便宜的航班](https://leetcode.cn/problems/cheapest-flights-within-k-stops/) | | 深度优先搜索、广度优先搜索、图、动态规划、最短路、堆(优先队列) | 中等 | | ||
| 1631 | [最小体力消耗路径](https://leetcode.cn/problems/path-with-minimum-effort/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1631.%20%E6%9C%80%E5%B0%8F%E4%BD%93%E5%8A%9B%E6%B6%88%E8%80%97%E8%B7%AF%E5%BE%84.md) | 深度优先搜索、广度优先搜索、并查集、数组、二分查找、矩阵、堆(优先队列) | 中等 | | ||
| 1786 | [从第一个节点出发到最后一个节点的受限路径数](https://leetcode.cn/problems/number-of-restricted-paths-from-first-to-last-node/) | | 图、拓扑排序、动态规划、最短路、堆(优先队列) | 中等 | | ||
|
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
...nts/08.Graph/04.Graph-Shortest-Path/05.Graph-Multi-Source-Shortest-Path-List.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### 多源最短路径题目 | ||
|
||
| 题号 | 标题 | 题解 | 标签 | 难度 | | ||
| :------ | :------ | :------ | :------ | :------ | | ||
| 0815 | [公交路线](https://leetcode.cn/problems/bus-routes/) | | 广度优先搜索、数组、哈希表 | 困难 | | ||
| 1162 | [地图分析](https://leetcode.cn/problems/as-far-from-land-as-possible/) | | 广度优先搜索、数组、动态规划、矩阵 | 中等 | | ||
|
Empty file removed
0
Contents/08.Graph/04.Graph-Shortest-Path/06.Graph-Multi-Source-Shortest-Path.md
Empty file.
File renamed without changes.
Empty file.
6 changes: 6 additions & 0 deletions
6
Contents/08.Graph/04.Graph-Shortest-Path/07.Graph-The-Second-Shortest-Path-List.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
### 次短路径题目 | ||
|
||
| 题号 | 标题 | 题解 | 标签 | 难度 | | ||
| :------ | :------ | :------ | :------ | :------ | | ||
| 2045 | [到达目的地的第二短时间](https://leetcode.cn/problems/second-minimum-time-to-reach-destination/) | | 广度优先搜索、图、最短路 | 困难 | | ||
|
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
....Graph/04.Graph-Shortest-Path/09.Graph-System-Of-Difference-Constraints-List.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### 差分约束系统 | ||
|
||
| 题号 | 标题 | 题解 | 标签 | 难度 | | ||
| :------ | :------ | :------ | :------ | :------ | | ||
| 0995 | [K 连续位的最小翻转次数](https://leetcode.cn/problems/minimum-number-of-k-consecutive-bit-flips/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/0995.%20K%20%E8%BF%9E%E7%BB%AD%E4%BD%8D%E7%9A%84%E6%9C%80%E5%B0%8F%E7%BF%BB%E8%BD%AC%E6%AC%A1%E6%95%B0.md) | 位运算、队列、数组、前缀和、滑动窗口 | 困难 | | ||
| 1109 | [航班预订统计](https://leetcode.cn/problems/corporate-flight-bookings/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1109.%20%E8%88%AA%E7%8F%AD%E9%A2%84%E8%AE%A2%E7%BB%9F%E8%AE%A1.md) | 数组、前缀和 | 中等 | | ||
|
Empty file.
Empty file removed
0
...ts/08.Graph/04.Graph-Shortest-Path/11.Graph-System-Of-Difference-Constraints.md
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters