File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -278,10 +278,11 @@ leetcode 题解,记录自己的 leetcode 解题之路。
278
278
- [ 哈夫曼编码和游程编码] ( ./thinkings/run-length-encode-and-huffman-encode.md )
279
279
- [ 布隆过滤器] ( ./thinkings/bloom-filter.md )
280
280
- [ 字符串问题] ( ./thinkings/string-problems.md )
281
- - [ 前缀树专题] ( ./thinkings/trie.md ) 🆕
281
+ - [ 前缀树专题] ( ./thinkings/trie.md )
282
282
- [ 《日程安排》专题] ( https://lucifer.ren/blog/2020/02/03/leetcode-%E6%88%91%E7%9A%84%E6%97%A5%E7%A8%8B%E5%AE%89%E6%8E%92%E8%A1%A8%E7%B3%BB%E5%88%97/ ) 🆕
283
283
- [ 《构造二叉树》专题] ( https://lucifer.ren/blog/2020/02/08/%E6%9E%84%E9%80%A0%E4%BA%8C%E5%8F%89%E6%A0%91%E4%B8%93%E9%A2%98/ ) 🆕
284
284
- [ 《贪婪策略》专题] ( ./thinkings/greedy.md ) 🆕
285
+ - [ 《深度优先遍历》专题] ( ./thinkings/DFS.md ) 🆕
285
286
286
287
### anki 卡片
287
288
Original file line number Diff line number Diff line change
1
+ # 深度优先遍历
2
+
3
+ 深度优先搜索算法(英语:Depth-First-Search,DFS)是一种用于遍历或搜索树或图的算法。沿着树的深度遍历树的节点,尽可能深的搜索树的分支。当节点 v 的所在边都己被探寻过,搜索将回溯到发现节点 v 的那条边的起始节点。这一过程一直进行到已发现从源节点可达的所有节点为止。如果还存在未被发现的节点,则选择其中一个作为源节点并重复以上过程,整个进程反复进行直到所有节点都被访问为止。属于盲目搜索。
4
+
5
+ 深度优先搜索是图论中的经典算法,利用深度优先搜索算法可以产生目标图的相应拓扑排序表,利用拓扑排序表可以方便的解决很多相关的图论问题,如最大路径问题等等。
6
+
7
+ 因发明「深度优先搜索算法」,约翰 · 霍普克洛夫特与罗伯特 · 塔扬在 1986 年共同获得计算机领域的最高奖:图灵奖。
8
+
9
+ 截止目前(2020-02-21),深度优先遍历在 LeetCode 中的题目是 129 道。在 LeetCode 中的题型绝对是超级大户了。而对于树的题目,我们基本上都可以使用 DFS 来解决,甚至我们可以基于 DFS 来做广度优先遍历。并不一定说 DFS 不可以做 BFS(广度优先遍历)的事情。而且由于 DFS 通常我们可以基于递归去做,因此算法会更简洁。 在对性能有很高邀请的场合,我建议你使用迭代,否则尽量使用递归,不仅写起来简单快速,还不容易出错。
10
+
11
+ 另外深度优先遍历可以结合回溯专题来联系,建议将这两个专题放到一起来学习。
12
+
13
+ ## 题目
14
+
15
+ 这是我近期总结的几个 DFS 题目,后续会持续更新~
16
+
17
+ - [ 200. 岛屿数量] ( https://leetcode-cn.com/problems/number-of-islands/solution/mo-ban-ti-dao-yu-dfspython3-by-fe-lucifer-2/ ) 中等
18
+
19
+ - [ 695. 岛屿的最大面积] ( https://leetcode-cn.com/problems/max-area-of-island/solution/mo-ban-ti-dao-yu-dfspython3-by-fe-lucifer/ ) 中等
20
+ - [ 979. 在二叉树中分配硬币] ( https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/solution/tu-jie-dfspython3-by-fe-lucifer/ ) 中等
You can’t perform that action at this time.
0 commit comments