mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-26 13:06:07 +00:00
build
This commit is contained in:
@@ -18,6 +18,8 @@ comments: true
|
||||
|
||||

|
||||
|
||||
<p align="center"> Fig. 图的广度优先遍历 </p>
|
||||
|
||||
### 算法实现
|
||||
|
||||
BFS 常借助「队列」来实现。队列具有“先入先出”的性质,这与 BFS “由近及远”的思想是异曲同工的。
|
||||
@@ -256,6 +258,8 @@ BFS 常借助「队列」来实现。队列具有“先入先出”的性质,
|
||||
|
||||

|
||||
|
||||
<p align="center"> Fig. 图的深度优先遍历 </p>
|
||||
|
||||
### 算法实现
|
||||
|
||||
这种“走到头 + 回溯”的算法形式一般基于递归来实现。与 BFS 类似,在 DFS 中我们也需要借助一个哈希表 `visited` 来记录已被访问的顶点,以避免重复访问顶点。
|
||||
|
||||
Reference in New Issue
Block a user