Skip to content

Commit cdb4281

Browse files
committed
Deployed d01b9a3 with MkDocs version: 0.17.3
1 parent 02cbd5a commit cdb4281

File tree

9 files changed

+222
-47
lines changed

9 files changed

+222
-47
lines changed

07_哈希表/hashtable/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ <h1 id="collision">哈希冲突 (collision)</h1>
293293
i = 1
294294
while index in inserted_index_set: # 如果计算发现已经占用,继续计算得到下一个可用槽的位置
295295
print('\th({number}) = {number} % M = {index} collision'.format(number=number, index=index))
296-
index = (first_index + i*i) % M
296+
index = (first_index + i*i) % M # 根据二次方探查的公式重新计算下一个需要插入的位置
297297
i += 1
298298
else:
299299
print('h({number}) = {number} % M = {index}'.format(number=number, index=index))

08_字典/dict/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ <h1 id="hashable">Hashable</h1>
257257
<h1 id="_1">思考题:</h1>
258258
<ul>
259259
<li>你能在哈希表的基础上实现 dict 的其他操作吗?</li>
260-
<li>对于 python 来说,哪些内置数据类型是可哈希的呢?</li>
261-
<li>你了解 python 的 hash 函数吗?</li>
260+
<li>对于 python 来说,哪些内置数据类型是可哈希的呢?list, dict, tuple, set 等类型哪些可以作为字典的 key 呢?</li>
261+
<li>你了解可变对象和不可变对象的区别吗?</li>
262+
<li>你了解 python 的 hash 函数吗?你了解 python 的<code>__hash__</code><code>__eq__</code> 魔术方法吗?它们何时被调用</li>
262263
</ul>
263264
<h1 id="_2">延伸阅读</h1>
264265
<p>阅读 python 文档关于 dict 的相关内容</p>

18_图与图的遍历/graph.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from collections import deque
4+
5+
6+
GRAPH = {
7+
'A': ['B', 'F'],
8+
'B': ['C', 'I', 'G'],
9+
'C': ['B', 'I', 'D'],
10+
'D': ['C', 'I', 'G', 'H', 'E'],
11+
'E': ['D', 'H', 'F'],
12+
'F': ['A', 'G', 'E'],
13+
'G': ['B', 'F', 'H', 'D'],
14+
'H': ['G', 'D', 'E'],
15+
'I': ['B', 'C', 'D'],
16+
}
17+
18+
19+
class Queue(object):
20+
def __init__(self):
21+
self._deque = deque()
22+
23+
def push(self, value):
24+
return self._deque.append(value)
25+
26+
def pop(self):
27+
return self._deque.popleft()
28+
29+
def __len__(self):
30+
return len(self._deque)
31+
32+
33+
def bfs(graph, start):
34+
search_queue = Queue()
35+
search_queue.push(start)
36+
searched = set()
37+
while search_queue: # 队列不为空就继续
38+
cur_node = search_queue.pop()
39+
if cur_node not in searched:
40+
print(cur_node)
41+
searched.add(cur_node)
42+
for node in graph[cur_node]:
43+
search_queue.push(node)
44+
45+
46+
print('bfs:')
47+
bfs(GRAPH, 'A')
48+
49+
50+
DFS_SEARCHED = set()
51+
52+
53+
def dfs(graph, start):
54+
if start not in DFS_SEARCHED:
55+
print(start)
56+
DFS_SEARCHED.add(start)
57+
for node in graph[start]:
58+
if node not in DFS_SEARCHED:
59+
dfs(graph, node)
60+
61+
62+
print('dfs:')
63+
dfs(GRAPH, 'A')
64+
65+
66+
class Stack(object):
67+
def __init__(self):
68+
self._deque = deque()
69+
70+
def push(self, value):
71+
return self._deque.append(value)
72+
73+
def pop(self):
74+
return self._deque.pop()
75+
76+
def __len__(self):
77+
return len(self._deque)
78+
79+
80+
def dfs_use_stack(graph, start):
81+
stack = Stack()
82+
stack.push(start)
83+
searched = set()
84+
while stack:
85+
cur_node = stack.pop()
86+
if cur_node not in searched:
87+
print(cur_node)
88+
searched.add(cur_node)
89+
# 请读者思考这里我为啥加了 reversed,其实不加上是可以的,你看下代码输出
90+
for node in reversed(graph[cur_node]):
91+
stack.push(node)
92+
93+
94+
print('dfs_use_stack:')
95+
dfs_use_stack(GRAPH, 'A')

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

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,64 @@ <h3 id="bfs">BFS</h3>
318318
for node in graph[cur_node]:
319319
search_queue.push(node)
320320

321-
322-
print(list(bfs(GRAPH, 'A'))) # 输出 ['A', 'B', 'F', 'C', 'I', 'G', 'E', 'D', 'H']
321+
print('bfs:')
322+
bfs(GRAPH, 'A')
323+
&quot;&quot;&quot;
324+
bfs:
325+
A
326+
B
327+
F
328+
C
329+
I
330+
G
331+
E
332+
D
333+
H
334+
&quot;&quot;&quot;
323335
</code></pre>
324336

325337
<p><img alt="" src="../bfs.png" /></p>
326338
<h3 id="dfs">DFS</h3>
339+
<p>深度优先搜索(DFS)是每遇到一个节点,如果没有被访问过,就直接去访问它的邻居节点,不断加深。代码其实很简单:</p>
340+
<pre><code>DFS_SEARCHED = set()
341+
342+
343+
def dfs(graph, start):
344+
if start not in DFS_SEARCHED:
345+
print(start)
346+
DFS_SEARCHED.add(start)
347+
for node in graph[start]:
348+
if node not in DFS_SEARCHED:
349+
dfs(graph, node)
350+
351+
352+
print('dfs:')
353+
dfs(GRAPH, 'A')
354+
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;
371+
</code></pre>
372+
327373
<h1 id="_5">思考题</h1>
374+
<ul>
375+
<li>DFS 中我们使用到了递归,请你用栈来改写这个函数?</li>
376+
</ul>
328377
<h1 id="_6">延伸阅读</h1>
378+
<p>图的算法还有很多,这里就不一一列举了,感兴趣的读者可以继续阅读一下材料。</p>
329379
<ul>
330380
<li><a href="https://www.zybuluo.com/guoxs/note/249812">数据结构之图</a></li>
331381
<li>《算法图解》第六章</li>

19_python内置常用算法和数据结构/builtins/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,15 @@
213213
<div class="section">
214214

215215
<h1 id="python">Python 常用内置算法和数据结构</h1>
216-
<p>之前在每章的数据结构和算法中涉及到的章节我都会提到对应的 python 内置模块,一般如果内置的可以满足需求,我们优先使用内置模块,一般在性能和容错性方面要好于我们自己实现。(比如有些是 c 实现的),这里我们重新列举一下。</p>
216+
<p>相信到这里大家对常用的数据结构和算法及其实现都比较熟悉了。
217+
之前在每章的数据结构和算法中涉及到的章节我都会提到对应的 python 内置模块,一般如果内置的可以满足需求,我们优先使用内置模块,
218+
因为在性能和容错性方面内置模块要好于我们自己实现(比如有些是 c 实现的)。本章我们不会再对每个模块的原理详细说明,仅列举出一些常见模块供大家参考,
219+
如果有需要最好的学习方式就是参考 Python 的官方文档。很多高级的数据结构我们也可以通过 google 搜索现成的库拿来直接用。</p>
220+
<ul>
221+
<li>collections</li>
222+
<li>heapq</li>
223+
<li>bisect</li>
224+
</ul>
217225
<h1 id="_1">结语</h1>
218226
<p>这套教程列举的算法很有限,包括图算法、贪心,动态规划,机器学习算法等很多没有涉及到,因为它们确实需要读者更深入的理论基础,而且这套教程的目的也不是针对算法竞赛。
219227
不过了解了本教程涉及到的大部分算法是可以应付绝大多数的业务开发的。如果读者对算法有兴趣,本教程引用的几本参考书都可以去深入学习。希望本教程能对你学习算法、养成良好的思维方式和编码习惯等有所帮助。</p>

20_面试指南/interview/index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@
171171
<a class="current" href="./">20_面试指南</a>
172172
<ul class="subnav">
173173

174+
<li class="toctree-l2"><a href="#_1">白板编程</a></li>
175+
176+
177+
<li class="toctree-l2"><a href="#_2">结语</a></li>
178+
179+
174180
</ul>
175181
</li>
176182

@@ -206,7 +212,11 @@
206212
<div role="main">
207213
<div class="section">
208214

209-
215+
<h1 id="_1">白板编程</h1>
216+
<p>其实我个人是反对出纯算法题目的,尤其是有些比较刁钻的直接出算法竞赛题,这对与很多做工程的同学来说是比较吃亏的。</p>
217+
<h1 id="_2">结语</h1>
218+
<p>这套教程列举的算法很有限,包括图算法、贪心,动态规划,机器学习算法等很多没有涉及到,因为它们确实需要读者更深入的理论基础,而且这套教程的目的也不是针对算法竞赛。
219+
不过了解了本教程涉及到的大部分算法是可以应付绝大多数的业务开发的。如果读者对算法有兴趣,本教程引用的几本参考书都可以去深入学习。希望本教程能对你学习算法、养成良好的思维方式和编码习惯等有所帮助。</p>
210220

211221
</div>
212222
</div>

index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ <h2 id="_18">勘误</h2>
406406
文字内容讲义放到 github 上,供大家免费查阅。</p>
407407
<p>如果你觉得文字内容或者视频内容有错误,欢迎在 github 上提 issue 讨论,我会修正相关内容,防止产生误导。</p>
408408
<h2 id="_19">本电子书制作和写作方式</h2>
409-
<p>使用 mkdocs 和 markdown 构建,使用 Python-Markdown-Math 完成数学公式</p>
409+
<p>使用 mkdocs 和 markdown 构建,使用 Python-Markdown-Math 完成数学公式。
410+
markdown 语法参考:http://xianbai.me/learn-md/article/about/readme.html</p>
410411
<p>安装依赖:</p>
411412
<pre><code class="sh">pip install mkdocs # 制作电子书, http://markdown-docs-zh.readthedocs.io/zh_CN/latest/
412413
# https://stackoverflow.com/questions/27882261/mkdocs-and-mathjax/31874157
@@ -478,5 +479,5 @@ <h2 id="_19">本电子书制作和写作方式</h2>
478479

479480
<!--
480481
MkDocs version : 0.17.3
481-
Build Date UTC : 2018-05-07 15:37:07
482+
Build Date UTC : 2018-05-09 00:44:23
482483
-->

search/search_index.json

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

0 commit comments

Comments
 (0)