Skip to content

Commit 1df309e

Browse files
committed
Deployed 21c122a with MkDocs version: 0.17.3
1 parent cb826c8 commit 1df309e

File tree

6 files changed

+43
-59
lines changed

6 files changed

+43
-59
lines changed

17_二叉查找树/binary_search_tree/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@
240240
<div class="section">
241241

242242
<h1 id="bst">二叉查找树(BST)</h1>
243-
<p>二叉树的一种应用就是来实现堆,今天我们再看看用二叉查找树。
244-
前面有章节说到了查找操作,包括线性查找和二分查找,线性查找效率比较低,二分又要求必须是有序的序列,
245-
为了维持有序插入的代价比较高。能不能有一种插入和查找都比较快的数据结构呢?二叉查找树就是这样一种结构,可以高效地插入和查询节点。</p>
243+
<p>二叉树的一种应用就是来实现堆,今天我们再看看用二叉查找树(Binary Search Tree, BST)
244+
前面有章节说到了查找操作,包括线性查找、二分查找、哈希查找等,线性查找效率比较低,二分又要求必须是有序的序列,
245+
为了维持有序插入的代价比较高、哈希查找效率很高但是浪费空间。能不能有一种插入和查找都比较快的数据结构呢?二叉查找树就是这样一种结构,可以高效地插入和查询节点。</p>
246246
<h1 id="bst_1">BST 定义</h1>
247247
<p>二叉查找树是这样一种二叉树结构,它的每个节点包含一个 key 和它附带的数据,对于每个内部节点 V:</p>
248248
<ul>
@@ -394,7 +394,7 @@ <h4 id="_6">删除有两个孩子的内部节点</h4>
394394
<p><img alt="" src="../predecessor_successor.png" /></p>
395395
<p>12 在中序遍历中的逻辑前任和后继分别是 4 和 23 节点。于是我们还有一种方法来删除 12 这个节点:</p>
396396
<ul>
397-
<li>找到节点待删除节点 N(12) 的后继节点 S(23)</li>
397+
<li>找到待删除节点 N(12) 的后继节点 S(23)</li>
398398
<li>复制节点 S 到节点 N</li>
399399
<li>删除节点 S</li>
400400
</ul>
@@ -413,14 +413,14 @@ <h4 id="_6">删除有两个孩子的内部节点</h4>
413413
subtree.right = self._bst_remove(subtree.right, key)
414414
return subtree
415415
else: # 找到了需要删除的节点
416-
if subtree.left is None and subtree.right is None: # left node
416+
if subtree.left is None and subtree.right is None: # 叶节点,返回 None 把其父亲指向它的指针置为 None
417417
return None
418418
elif subtree.left is None or subtree.right is None: # 只有一个孩子
419419
if subtree.left is not None:
420-
return subtree.left
420+
return subtree.left # 返回它的孩子并让它的父亲指过去
421421
else:
422422
return subtree.right
423-
else: # 俩孩子
423+
else: # 俩孩子,寻找后继节点替换
424424
successor_node = self._bst_min_node(subtree.right)
425425
subtree.key, subtree.value = successor_node.key, subtree.value
426426
subtree.right = self._bst_remove(subtree.right, successor_node.key)

17_二叉查找树/bst.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ def _bst_remove(self, subtree, key):
9797
subtree.right = self._bst_remove(subtree.right, key)
9898
return subtree
9999
else: # 找到了需要删除的节点
100-
if subtree.left is None and subtree.right is None: # left node
100+
if subtree.left is None and subtree.right is None: # 叶节点,返回 None 把其父亲指向它的指针置为 None
101101
return None
102102
elif subtree.left is None or subtree.right is None: # 只有一个孩子
103103
if subtree.left is not None:
104-
return subtree.left
104+
return subtree.left # 返回它的孩子并让它的父亲指过去
105105
else:
106106
return subtree.right
107-
else: # 俩孩子
107+
else: # 俩孩子,寻找后继节点替换
108108
successor_node = self._bst_min_node(subtree.right)
109109
subtree.key, subtree.value = successor_node.key, subtree.value
110110
subtree.right = self._bst_remove(subtree.right, successor_node.key)

18_图与图的遍历/graph/index.html

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -350,29 +350,13 @@ <h3 id="dfs">DFS</h3>
350350

351351

352352
print('dfs:')
353-
dfs(GRAPH, 'A')
353+
dfs(GRAPH, 'A') # A B C I D G F E H
354354

355-
&quot;&quot;&quot;
356-
DFS_SEARCHED = set()
357-
358-
359-
def dfs(graph, start):
360-
if start not in DFS_SEARCHED:
361-
print(start)
362-
DFS_SEARCHED.add(start)
363-
for node in graph[start]:
364-
if node not in DFS_SEARCHED:
365-
dfs(graph, node) # 递归访问邻居节点
366-
367-
368-
print('dfs:')
369-
dfs(GRAPH, 'A')
370-
&quot;&quot;&quot;
371355
</code></pre>
372356

373357
<h1 id="_5">思考题</h1>
374358
<ul>
375-
<li>DFS 中我们使用到了递归,请你用栈来改写这个函数?</li>
359+
<li>DFS 中我们使用到了递归,请你用栈来改写这个函数?(代码里有答案,我建议你先尝试自己实现)</li>
376360
</ul>
377361
<h1 id="_6">延伸阅读</h1>
378362
<p>图的算法还有很多,这里就不一一列举了,感兴趣的读者可以继续阅读一下材料。</p>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,5 +479,5 @@ <h2 id="_19">本电子书制作和写作方式</h2>
479479

480480
<!--
481481
MkDocs version : 0.17.3
482-
Build Date UTC : 2018-05-25 00:05:58
482+
Build Date UTC : 2018-05-27 00:14:18
483483
-->

search/search_index.json

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

sitemap.xml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,111 @@
44

55
<url>
66
<loc>/</loc>
7-
<lastmod>2018-05-25</lastmod>
7+
<lastmod>2018-05-27</lastmod>
88
<changefreq>daily</changefreq>
99
</url>
1010

1111

1212

1313
<url>
1414
<loc>/00_课程简介之笨方法学算法/why_and_how_to_learn/</loc>
15-
<lastmod>2018-05-25</lastmod>
15+
<lastmod>2018-05-27</lastmod>
1616
<changefreq>daily</changefreq>
1717
</url>
1818

1919

2020

2121
<url>
2222
<loc>/01_抽象数据类型和面向对象编程/ADT_OOP/</loc>
23-
<lastmod>2018-05-25</lastmod>
23+
<lastmod>2018-05-27</lastmod>
2424
<changefreq>daily</changefreq>
2525
</url>
2626

2727

2828

2929
<url>
3030
<loc>/02_数组和列表/array_and_list/</loc>
31-
<lastmod>2018-05-25</lastmod>
31+
<lastmod>2018-05-27</lastmod>
3232
<changefreq>daily</changefreq>
3333
</url>
3434

3535

3636

3737
<url>
3838
<loc>/03_链表/linked_list/</loc>
39-
<lastmod>2018-05-25</lastmod>
39+
<lastmod>2018-05-27</lastmod>
4040
<changefreq>daily</changefreq>
4141
</url>
4242

4343

4444

4545
<url>
4646
<loc>/04_队列/queue/</loc>
47-
<lastmod>2018-05-25</lastmod>
47+
<lastmod>2018-05-27</lastmod>
4848
<changefreq>daily</changefreq>
4949
</url>
5050

5151

5252

5353
<url>
5454
<loc>/05_栈/stack/</loc>
55-
<lastmod>2018-05-25</lastmod>
55+
<lastmod>2018-05-27</lastmod>
5656
<changefreq>daily</changefreq>
5757
</url>
5858

5959

6060

6161
<url>
6262
<loc>/06_算法分析/big_o/</loc>
63-
<lastmod>2018-05-25</lastmod>
63+
<lastmod>2018-05-27</lastmod>
6464
<changefreq>daily</changefreq>
6565
</url>
6666

6767

6868

6969
<url>
7070
<loc>/07_哈希表/hashtable/</loc>
71-
<lastmod>2018-05-25</lastmod>
71+
<lastmod>2018-05-27</lastmod>
7272
<changefreq>daily</changefreq>
7373
</url>
7474

7575

7676

7777
<url>
7878
<loc>/08_字典/dict/</loc>
79-
<lastmod>2018-05-25</lastmod>
79+
<lastmod>2018-05-27</lastmod>
8080
<changefreq>daily</changefreq>
8181
</url>
8282

8383

8484

8585
<url>
8686
<loc>/09_集合/set/</loc>
87-
<lastmod>2018-05-25</lastmod>
87+
<lastmod>2018-05-27</lastmod>
8888
<changefreq>daily</changefreq>
8989
</url>
9090

9191

9292

9393
<url>
9494
<loc>/10_递归/recursion/</loc>
95-
<lastmod>2018-05-25</lastmod>
95+
<lastmod>2018-05-27</lastmod>
9696
<changefreq>daily</changefreq>
9797
</url>
9898

9999

100100

101101
<url>
102102
<loc>/11_线性查找与二分查找/search/</loc>
103-
<lastmod>2018-05-25</lastmod>
103+
<lastmod>2018-05-27</lastmod>
104104
<changefreq>daily</changefreq>
105105
</url>
106106

107107

108108

109109
<url>
110110
<loc>/12_基本排序算法/basic_sort/</loc>
111-
<lastmod>2018-05-25</lastmod>
111+
<lastmod>2018-05-27</lastmod>
112112
<changefreq>daily</changefreq>
113113
</url>
114114

@@ -117,19 +117,19 @@
117117

118118
<url>
119119
<loc>/13_高级排序算法/advanced_sorting/</loc>
120-
<lastmod>2018-05-25</lastmod>
120+
<lastmod>2018-05-27</lastmod>
121121
<changefreq>daily</changefreq>
122122
</url>
123123

124124
<url>
125125
<loc>/13_高级排序算法/merge_sort/</loc>
126-
<lastmod>2018-05-25</lastmod>
126+
<lastmod>2018-05-27</lastmod>
127127
<changefreq>daily</changefreq>
128128
</url>
129129

130130
<url>
131131
<loc>/13_高级排序算法/quick_sort/</loc>
132-
<lastmod>2018-05-25</lastmod>
132+
<lastmod>2018-05-27</lastmod>
133133
<changefreq>daily</changefreq>
134134
</url>
135135

@@ -138,55 +138,55 @@
138138

139139
<url>
140140
<loc>/14_树与二叉树/tree/</loc>
141-
<lastmod>2018-05-25</lastmod>
141+
<lastmod>2018-05-27</lastmod>
142142
<changefreq>daily</changefreq>
143143
</url>
144144

145145

146146

147147
<url>
148148
<loc>/15_堆与堆排序/heap_and_heapsort/</loc>
149-
<lastmod>2018-05-25</lastmod>
149+
<lastmod>2018-05-27</lastmod>
150150
<changefreq>daily</changefreq>
151151
</url>
152152

153153

154154

155155
<url>
156156
<loc>/16_优先级队列/priority_queue/</loc>
157-
<lastmod>2018-05-25</lastmod>
157+
<lastmod>2018-05-27</lastmod>
158158
<changefreq>daily</changefreq>
159159
</url>
160160

161161

162162

163163
<url>
164164
<loc>/17_二叉查找树/binary_search_tree/</loc>
165-
<lastmod>2018-05-25</lastmod>
165+
<lastmod>2018-05-27</lastmod>
166166
<changefreq>daily</changefreq>
167167
</url>
168168

169169

170170

171171
<url>
172172
<loc>/18_图与图的遍历/graph/</loc>
173-
<lastmod>2018-05-25</lastmod>
173+
<lastmod>2018-05-27</lastmod>
174174
<changefreq>daily</changefreq>
175175
</url>
176176

177177

178178

179179
<url>
180180
<loc>/19_python内置常用算法和数据结构/builtins/</loc>
181-
<lastmod>2018-05-25</lastmod>
181+
<lastmod>2018-05-27</lastmod>
182182
<changefreq>daily</changefreq>
183183
</url>
184184

185185

186186

187187
<url>
188188
<loc>/20_面试指南/interview/</loc>
189-
<lastmod>2018-05-25</lastmod>
189+
<lastmod>2018-05-27</lastmod>
190190
<changefreq>daily</changefreq>
191191
</url>
192192

0 commit comments

Comments
 (0)